{"record":{"id":"10d0de438e3fa087","repo":"hyperledger/fabric","slug":"did-not-find-file-s-in-package","errorCode":null,"errorMessage":"did not find file '%s' in package","messagePattern":"did not find file '(.+?)' in package","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/persistence/chaincode_package.go","lineNumber":203,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"error inspecting next tar header\")\n\t\t}\n\n\t\tif header.Name != name {\n\t\t\tcontinue\n\t\t}\n\n\t\tif header.Typeflag != tar.TypeReg {\n\t\t\treturn nil, errors.Errorf(\"tar entry %s is not a regular file, type %v\", header.Name, header.Typeflag)\n\t\t}\n\n\t\treturn &TarFileStream{\n\t\t\tTarFile:    tarReader,\n\t\t\tFileStream: file,\n\t\t}, nil\n\t}\n\n\treturn nil, errors.Errorf(\"did not find file '%s' in package\", name)\n}\n\ntype TarFileStream struct {\n\tTarFile    io.Reader\n\tFileStream io.Closer\n}\n\nfunc (tfs *TarFileStream) Read(p []byte) (int, error) {\n\treturn tfs.TarFile.Read(p)\n}\n\nfunc (tfs *TarFileStream) Close() error {\n\treturn tfs.FileStream.Close()\n}\n\n// ChaincodePackage represents the un-tar-ed format of the chaincode package.\ntype ChaincodePackage struct {\n\tMetadata    *ChaincodePackageMetadata","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/persistence/chaincode_package.go#L185-L221","documentation":"After iterating every entry of the package tar without finding one named exactly 'name', the File helper returns this error. The gzip/tar layers are fine; the requested file simply is not present in the archive. Callers use this for metadata.json and code.tar, so a package missing either will surface this.","triggerScenarios":"Metadata() or MetadataBytes() when the tar has no 'metadata.json' entry; Code() when there is no 'code.tar' entry — e.g. packages built with different entry names or missing components.","commonSituations":"Manual packaging that named files differently (META-INF/meta.json, chaincode.tar), packages produced by mismatched fabric versions, or archives where an antivirus/cleanup step stripped files.","solutions":["Check the archive contents: tar -tzvf <package> and confirm 'metadata.json' / 'code.tar' exist with exact names.","Repackage with 'peer lifecycle chaincode package' to get canonical entry names.","Rename entries to the expected MetadataFile/CodePackageFile names and rebuild the tar.","Ensure you packaged at the correct directory level so files land at tar root, not nested in subfolders."],"exampleFix":"// before: nested entries, not found at tar root\ntar -czf mycc.tgz ./pkg/*   // entries named pkg/metadata.json\n// after: entries at root\ncd pkg && tar -czf ../mycc.tgz metadata.json code.tar","handlingStrategy":"validation","validationCode":"names := map[string]bool{}\nif out, err := exec.Command(\"tar\", \"-tzf\", pkgPath).Output(); err == nil {\n\tfor _, n := range strings.Fields(string(out)) { names[filepath.Base(n)] = true }\n}\nif !names[\"metadata.json\"] || !names[\"code.tar\"] {\n\treturn fmt.Errorf(\"package %s missing metadata.json or code.tar\", pkgPath)\n}","typeGuard":null,"tryCatchPattern":"meta, err := p.Metadata(pkgPath)\nif err != nil {\n\tif strings.Contains(err.Error(), \"did not find file\") {\n\t\treturn fmt.Errorf(\"%s is missing required entries; repackage with peer lifecycle chaincode package\", pkgPath)\n\t}\n\treturn err\n}","preventionTips":["Verify 'tar -tzf' lists exactly metadata.json and code.tar at the root.","Never rename entries inside a package.","Tar from inside the package directory so entries are not path-prefixed.","Match the fabric version's expected package layout."],"tags":["tar","chaincode-package","missing-file"],"backgroundTag":"missing-file-in-archive","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}