{"record":{"id":"794e7da7f6b011bd","repo":"hyperledger/fabric","slug":"uninitialized-package-794e7d","errorCode":null,"errorMessage":"uninitialized package","messagePattern":"uninitialized package","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccprovider/sigcdspackage.go","lineNumber":184,"sourceCode":"\t}\n\n\thash.Reset()\n\n\t// compute the id\n\thash.Write(scdsdata.CodeHash)\n\thash.Write(scdsdata.MetaDataHash)\n\thash.Write(scdsdata.SignatureHash)\n\n\tid := hash.Sum(nil)\n\n\treturn b, id, scdsdata, nil\n}\n\n// ValidateCC returns error if the chaincode is not found or if its not a\n// ChaincodeDeploymentSpec\nfunc (ccpack *SignedCDSPackage) ValidateCC(ccdata *ChaincodeData) error {\n\tif ccpack.sDepSpec == nil {\n\t\treturn errors.New(\"uninitialized package\")\n\t}\n\n\tif ccpack.sDepSpec.ChaincodeDeploymentSpec == nil {\n\t\treturn errors.New(\"signed chaincode deployment spec cannot be nil in a package\")\n\t}\n\n\tif ccpack.depSpec == nil {\n\t\treturn errors.New(\"chaincode deployment spec cannot be nil in a package\")\n\t}\n\n\t// This is a hack. LSCC expects a specific LSCC error when names are invalid so it\n\t// has its own validation code. We can't use that error because of import cycles.\n\t// Unfortunately, we also need to check if what have makes some sort of sense as\n\t// protobuf will gladly deserialize garbage and there are paths where we assume that\n\t// a successful unmarshal means everything works but, if it fails, we try to unmarshal\n\t// into something different.\n\tif !isPrintable(ccdata.Name) {\n\t\treturn fmt.Errorf(\"invalid chaincode name: %q\", ccdata.Name)","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccprovider/sigcdspackage.go#L166-L202","documentation":"SignedCDSPackage.ValidateCC (used by GetCCPackage to identify an uploaded package) returns 'uninitialized package' when the internal signed deployment spec (sDepSpec) has never been populated, i.e. InitFromBuffer/InitFromDependencySpec was never successfully called. It distinguishes 'never initialized' from 'initialized but invalid content'.","triggerScenarios":"Calling ValidateCC (directly or via GetCCPackage) on a fresh &SignedCDSPackage{} with no prior successful InitFromBuffer/InitFromDependencySpec; a previous InitFromBuffer failed partway leaving sDepSpec nil.","commonSituations":"A package loader that created the wrapper but skipped initialization; an error from an earlier InitFromBuffer swallowed or ignored; unit tests constructing the struct directly and validating immediately.","solutions":["Call InitFromBuffer (or InitFromDependencySpec) on the SignedCDSPackage and check its error before invoking ValidateCC.","If a prior InitFromBuffer failed, fix that underlying error first (bad bytes, BCCSP init failure, nil policy) — ValidateCC will then work.","Ensure the right package type is used: validating a plain CDSPackage payload as a SignedCDSPackage will appear as uninitialized.","In tests, build the package through the normal init path rather than instantiating the struct bare."],"exampleFix":"// before\npack := &ccprovider.SignedCDSPackage{}\nerr = pack.ValidateCC(ccdata)\n// after\npack := &ccprovider.SignedCDSPackage{}\nif err := pack.InitFromBuffer(buf, hasher); err != nil {\n    return err\n}\nerr = pack.ValidateCC(pack.GetChaincodeData())","handlingStrategy":"try-catch","validationCode":"pack := &ccprovider.SignedCDSPackage{}\nif err := pack.InitFromBuffer(buf, hasher); err != nil {\n    return fmt.Errorf(\"package init failed: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := pack.ValidateCC(ccdata); err != nil {\n    if err.Error() == \"uninitialized package\" {\n        // re-run InitFromBuffer/InitFromDependencySpec with the raw bytes\n    }\n    return err\n}","preventionTips":["Never call ValidateCC without a prior successful InitFromBuffer/InitFromDependencySpec.","Check the error returned by InitFromBuffer immediately; do not swallow it.","Route packages through GetCCPackage, which handles initialization order for you.","In tests, construct packages via the normal init path, not bare struct literals."],"tags":["chaincode","package-validation","fabric","uninitialized-state"],"backgroundTag":"uninitialized-chaincode-package","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"}