{"record":{"id":"45e3f9d12522a368","repo":"hyperledger/fabric","slug":"invalid-chaincode-deployment-spec","errorCode":null,"errorMessage":"invalid chaincode deployment spec","messagePattern":"invalid chaincode deployment spec","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccpackage/ccpackage.go","lineNumber":163,"sourceCode":"\t\t\t}\n\n\t\t} else if err = ValidateCip(baseCip, cip); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tif endorsementExists {\n\t\t\tendorsements[n] = cip.OwnerEndorsements[0]\n\t\t}\n\t}\n\n\treturn createSignedCCDepSpec(baseCip.ChaincodeDeploymentSpec, baseCip.InstantiationPolicy, endorsements)\n}\n\n// OwnerCreateSignedCCDepSpec creates a package from a ChaincodeDeploymentSpec and\n// optionally endorses it\nfunc OwnerCreateSignedCCDepSpec(cds *peer.ChaincodeDeploymentSpec, instPolicy *common.SignaturePolicyEnvelope, owner identity.SignerSerializer) (*common.Envelope, error) {\n\tif cds == nil {\n\t\treturn nil, errors.New(\"invalid chaincode deployment spec\")\n\t}\n\n\tif instPolicy == nil {\n\t\treturn nil, errors.New(\"must provide an instantiation policy\")\n\t}\n\n\tcdsbytes := protoutil.MarshalOrPanic(cds)\n\n\tinstpolicybytes := protoutil.MarshalOrPanic(instPolicy)\n\n\tvar endorsements []*peer.Endorsement\n\t// it is not mandatory (at this protoutil level) to have a signature\n\t// this is especially convenient during dev/test\n\t// it may be necessary to enforce it via a policy at a higher level\n\tif owner != nil {\n\t\t// serialize the signing identity\n\t\tendorser, err := owner.Serialize()\n\t\tif err != nil {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccpackage/ccpackage.go#L145-L181","documentation":"OwnerCreateSignedCCDepSpec builds a signed chaincode deployment package from a ChaincodeDeploymentSpec. It throws this when the cds argument is nil, since there is nothing to package or endorse. It is a fail-fast guard before any marshalling or signing occurs.","triggerScenarios":"Calling OwnerCreateSignedCCDepSpec(nil, instPolicy, owner), or passing a variable that was never populated by GetChaincodeDeploymentSpec/UnmarshalCDS (e.g. a failed or skipped spec parse left nil).","commonSituations":"Parsing a malformed chaincode install/instantiate payload where unmarshalling failed silently and the nil spec was forwarded; CLI or SDK callers building a SignedCDS without constructing the inner ChaincodeDeploymentSpec; tests that forgot to create a spec fixture.","solutions":["Construct a valid *peer.ChaincodeDeploymentSpec (e.g. via container/NewCCDeploymentSpec or by unmarshalling proto bytes) before calling","Check cds != nil (and that its ChaincodeSpec is populated) before invoking OwnerCreateSignedCCDepSpec","If the spec came from unmarshalling, check the unmarshal error first instead of proceeding with a nil result"],"exampleFix":"// before\nenv, err := ccpackage.OwnerCreateSignedCCDepSpec(cds, instPolicy, signer)\n// after\nif cds == nil || cds.ChaincodeSpec == nil {\n    return errors.New(\"chaincode deployment spec must be constructed before signing\")\n}\nenv, err := ccpackage.OwnerCreateSignedCCDepSpec(cds, instPolicy, signer)","handlingStrategy":"validation","validationCode":"if cds == nil || cds.ChaincodeSpec == nil {\n    return errors.New(\"chaincode deployment spec must be built before creating signed package\")\n}\nenv, err := ccpackage.OwnerCreateSignedCCDepSpec(cds, instPolicy, owner)","typeGuard":"func isCDSValid(cds *peer.ChaincodeDeploymentSpec) bool {\n    return cds != nil && cds.ChaincodeSpec != nil && cds.ChaincodeSpec.ChaincodeId != nil\n}","tryCatchPattern":"env, err := ccpackage.OwnerCreateSignedCCDepSpec(cds, instPolicy, owner)\nif err != nil {\n    if err.Error() == \"invalid chaincode deployment spec\" {\n        return fmt.Errorf(\"caller bug: nil CDS: %w\", err)\n    }\n    return err\n}","preventionTips":["Always construct the CDS through proto unmarshal helpers and check their errors","Assert non-nil spec in unit tests before signing","Never forward the result of an unmarshal that may return (nil, nil-ish state) without checking"],"tags":["hyperledger-fabric","chaincode","nil-argument","validation"],"backgroundTag":"nil-argument","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"}