{"record":{"id":"2185963c4f7a140f","repo":"hyperledger/fabric","slug":"uninitialized-package","errorCode":null,"errorMessage":"uninitialized package","messagePattern":"uninitialized package","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccprovider/cdspackage.go","lineNumber":145,"sourceCode":"\t\treturn nil, nil, nil, err\n\t}\n\n\thash.Reset()\n\n\t// compute the id\n\thash.Write(cdsdata.CodeHash)\n\thash.Write(cdsdata.MetaDataHash)\n\n\tid := hash.Sum(nil)\n\n\treturn b, id, cdsdata, nil\n}\n\n// ValidateCC returns error if the chaincode is not found or if its not a\n// ChaincodeDeploymentSpec\nfunc (ccpack *CDSPackage) ValidateCC(ccdata *ChaincodeData) error {\n\tif ccpack.depSpec == nil {\n\t\treturn errors.New(\"uninitialized package\")\n\t}\n\n\tif ccpack.data == nil {\n\t\treturn errors.New(\"nil data\")\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)\n\t}\n\n\tif ccdata.Name != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Name || ccdata.Version != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Version {\n\t\treturn fmt.Errorf(\"invalid chaincode data %v (%v)\", ccdata, ccpack.depSpec.ChaincodeSpec.ChaincodeId)","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccprovider/cdspackage.go#L127-L163","documentation":"CDSPackage.ValidateCC validates package contents against ChaincodeData. If the package's depSpec (ChaincodeDeploymentSpec) was never populated — InitFromBuffer/InitFromPath never succeeded — the package is 'uninitialized' and validation cannot proceed, so this error is returned.","triggerScenarios":"Calling ValidateCC on a zero-value CDSPackage{}, or on a CDSPackage whose InitFromBuffer/InitFromPath call failed earlier and whose error was ignored.","commonSituations":"Code constructing CDSPackage manually without initialization; ignoring the error from InitFromBuffer and continuing; test setups (TestValidateCCErrorPaths) exercising the error path.","solutions":["Call InitFromBuffer or InitFromPath successfully before ValidateCC","Check and handle the error returned by InitFromBuffer/InitFromPath instead of continuing","Ensure you are not reusing a CDSPackage that failed initialization in a prior step"],"exampleFix":"// before\nccpack := &CDSPackage{}\nerr := ccpack.ValidateCC(ccdata) // uninitialized\n// after\nccpack := &CDSPackage{}\nif _, err := ccpack.InitFromBuffer(buf); err != nil { return err }\nerr = ccpack.ValidateCC(ccdata)","handlingStrategy":"validation","validationCode":"func initializedPackage(ccpack *ccprovider.CDSPackage, buf []byte) (*ccprovider.CDSPackage, error) {\n    if _, err := ccpack.InitFromBuffer(buf); err != nil {\n        return nil, err\n    }\n    return ccpack, nil\n}","typeGuard":"func hasDepSpec(ccpack *ccprovider.CDSPackage) bool { return ccpack != nil } // plus always init via InitFromBuffer first","tryCatchPattern":"if _, err := ccpack.InitFromBuffer(buf); err != nil {\n    return fmt.Errorf(\"package init failed: %w\", err) // never proceed to ValidateCC uninitialized\n}\nif err := ccpack.ValidateCC(ccdata); err != nil {\n    return err\n}","preventionTips":["Never construct CDSPackage{} manually and call ValidateCC directly","Always check the error from InitFromBuffer/InitFromPath before validation","Use one initialization code path (InitFromBuffer or InitFromPath) consistently","Reuse the returned ChaincodeData from init instead of building your own"],"tags":["hyperledger-fabric","chaincode","initialization","validation"],"backgroundTag":"uninitialized-object","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"}