{"record":{"id":"b0c7ae69c25faeec","repo":"hyperledger/fabric","slug":"did-not-find-a-code-package-inside-the-package","errorCode":null,"errorMessage":"did not find a code package inside the package","messagePattern":"did not find a code package inside the package","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/persistence/chaincode_package.go","lineNumber":327,"sourceCode":"\n\t\tswitch header.Name {\n\n\t\tcase MetadataFile:\n\t\t\tccPackageMetadata = &ChaincodePackageMetadata{}\n\t\t\terr := json.Unmarshal(fileBytes, ccPackageMetadata)\n\t\t\tif err != nil {\n\t\t\t\treturn ccPackageMetadata, nil, errors.Wrapf(err, \"could not unmarshal %s as json\", MetadataFile)\n\t\t\t}\n\n\t\tcase CodePackageFile:\n\t\t\tcodePackage = fileBytes\n\t\tdefault:\n\t\t\tlogger.Warningf(\"Encountered unexpected file '%s' in top level of chaincode package\", header.Name)\n\t\t}\n\t}\n\n\tif codePackage == nil {\n\t\treturn ccPackageMetadata, nil, errors.Errorf(\"did not find a code package inside the package\")\n\t}\n\n\tif ccPackageMetadata == nil {\n\t\treturn ccPackageMetadata, nil, errors.Errorf(\"did not find any package metadata (missing %s)\", MetadataFile)\n\t}\n\n\tif err := ValidateLabel(ccPackageMetadata.Label); err != nil {\n\t\treturn ccPackageMetadata, nil, err\n\t}\n\n\treturn ccPackageMetadata, codePackage, nil\n}\n","sourceCodeStart":309,"sourceCodeEnd":340,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/persistence/chaincode_package.go#L309-L340","documentation":"ParseChaincodePackage iterates over the entries of a chaincode package tarball. When it finishes and never encountered a file other than the metadata file / label file (i.e. no actual code payload entry), it throws this error because the archive is not a valid chaincode package — it lacks the code package member.","triggerScenarios":"Calling Parse or PackageID on a tar archive whose top-level entries contain only MetadataFile (metadata.json) and LabelFile (label) but no code package file; or an archive where the payload entry was pruned/corrupted.","commonSituations":"Hand-crafting a chaincode package with a script that writes only metadata; a truncated tarball produced by a failed install; uploading the wrong archive (e.g. just a metadata descriptor) to `peer lifecycle chaincode install`.","solutions":["Repackage the chaincode with `peer lifecycle chaincode package` (or package.ChaincodePackage) so the archive contains the code payload alongside metadata.json and label","Verify the archive contents (e.g. `tar -tf <pkg>.tgz`) include a code package entry, not only metadata.json/label","Re-download or re-export the package if it was truncated in transit and confirm its checksum against the source"],"exampleFix":"// before: archive has only metadata\n// tar: metadata.json, label\n\n// after: build with the tool so the payload is included\npeer lifecycle chaincode package mycc.tar.gz --path ./src --lang golang --label mycc_1.0","handlingStrategy":"validation","validationCode":"entries, err := listTarTopLevel(pkgBytes)\nif err != nil { return err }\nhasMeta, hasPayload := false, false\nfor _, e := range entries {\n    if e == \"metadata.json\" { hasMeta = true } else { hasPayload = true }\n}\nif !hasMeta || !hasPayload { return errors.New(\"package missing metadata.json or code payload\") }","typeGuard":"func hasCodePackage(entries []string) bool {\n    for _, e := range entries {\n        if e != \"metadata.json\" && e != \"label\" { return true }\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Always build packages with `peer lifecycle chaincode package` rather than hand-rolled tar scripts","Verify package contents (tar -tf) and checksum before installing","Keep a canonical copy of released packages and install from that"],"tags":["chaincode","packaging","validation"],"backgroundTag":"missing-package-payload","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"}