{"record":{"id":"2341c3cbf0987db2","repo":"hyperledger/fabric","slug":"nil-data-bytes-2341c3","errorCode":null,"errorMessage":"nil data bytes","messagePattern":"nil data bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccprovider/sigcdspackage.go","lineNumber":302,"sourceCode":"\n\tif ccpack.id == nil {\n\t\treturn errors.New(\"id cannot be nil if buf is not nil\")\n\t}\n\n\tif ccpack.sDepSpec == nil || ccpack.depSpec == nil {\n\t\treturn errors.New(\"depspec cannot be nil if buf is not nil\")\n\t}\n\n\tif ccpack.env == nil {\n\t\treturn errors.New(\"env cannot be nil if buf and depspec are not nil\")\n\t}\n\n\tif ccpack.data == nil {\n\t\treturn errors.New(\"nil data\")\n\t}\n\n\tif ccpack.datab == nil {\n\t\treturn errors.New(\"nil data bytes\")\n\t}\n\n\tccname := ccpack.depSpec.ChaincodeSpec.ChaincodeId.Name\n\tccversion := ccpack.depSpec.ChaincodeSpec.ChaincodeId.Version\n\n\t// return error if chaincode exists\n\tpath := fmt.Sprintf(\"%s/%s.%s\", chaincodeInstallPath, ccname, ccversion)\n\tif _, err := os.Stat(path); err == nil {\n\t\treturn fmt.Errorf(\"chaincode %s exists\", path)\n\t}\n\n\tif err := os.WriteFile(path, ccpack.buf, 0o644); err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccprovider/sigcdspackage.go#L284-L320","documentation":"PutChaincodeToFS persists both the parsed data and its serialized byte form (datab). This error fires when datab — the raw serialized bytes corresponding to the package — is nil while data is non-nil. The serialized bytes are what get written to disk, so the library refuses to continue without them.","triggerScenarios":"A SignedCDSPackage built with the in-memory payload (data) but no serialized bytes (datab) — typically a package constructed in code or produced by a decoder path that skips the byte serialization step in processSignedCDS.","commonSituations":"Custom chaincode packaging tools, partial decoding of install packages after a Fabric upgrade, or tests that assemble package structs by hand.","solutions":["Serialize the package into ccpack.datab (e.g., proto.Marshal of the CDSPackage) before calling PutChaincodeToFS","Use the standard packaging flow (peer install / processSignedCDS) so datab is set automatically","Regenerate the chaincode package from source and reinstall"],"exampleFix":"// before\npack.data = parsed\npack.datab = nil\nccprovider.PutChaincodeToFS(pack) // errors: nil data bytes\n\n// after\npack.data = parsed\ndatab, err := proto.Marshal(pack)\nif err != nil { return err }\npack.datab = datab\nccprovider.PutChaincodeToFS(pack)","handlingStrategy":"validation","validationCode":"if pack != nil && pack.Data != nil && pack.Datab == nil {\n  return errors.New(\"package datab not serialized; marshal package first\")\n}","typeGuard":"func hasSerializedBytes(p *ccprovider.SignedCDSPackage) bool {\n  return p != nil && p.Datab != nil && len(p.Datab) > 0\n}","tryCatchPattern":"err := ccprovider.PutChaincodeToFS(pack)\nif err != nil {\n  if strings.Contains(err.Error(), \"nil data bytes\") {\n    datab, merr := proto.Marshal(pack)\n    if merr != nil { return merr }\n    pack.Datab = datab\n    return ccprovider.PutChaincodeToFS(pack)\n  }\n  return err\n}","preventionTips":["Always serialize (proto.Marshal) the package before persisting","Round-trip test: unmarshal(serialized) must yield identical fields","Avoid custom packaging code paths; use the SDK/peer CLI"],"tags":["chaincode-install","nil-check","fabric"],"backgroundTag":"nil-required-field","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"}