hyperledger/fabric · error
nil data bytes
Error message
nil data bytes
What it means
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.
Source
Thrown at core/common/ccprovider/sigcdspackage.go:302
if ccpack.id == nil {
return errors.New("id cannot be nil if buf is not nil")
}
if ccpack.sDepSpec == nil || ccpack.depSpec == nil {
return errors.New("depspec cannot be nil if buf is not nil")
}
if ccpack.env == nil {
return errors.New("env cannot be nil if buf and depspec are not nil")
}
if ccpack.data == nil {
return errors.New("nil data")
}
if ccpack.datab == nil {
return errors.New("nil data bytes")
}
ccname := ccpack.depSpec.ChaincodeSpec.ChaincodeId.Name
ccversion := ccpack.depSpec.ChaincodeSpec.ChaincodeId.Version
// return error if chaincode exists
path := fmt.Sprintf("%s/%s.%s", chaincodeInstallPath, ccname, ccversion)
if _, err := os.Stat(path); err == nil {
return fmt.Errorf("chaincode %s exists", path)
}
if err := os.WriteFile(path, ccpack.buf, 0o644); err != nil {
return err
}
return nil
}
View on GitHub (pinned to 2736b63f8f)
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
Example fix
// before
pack.data = parsed
pack.datab = nil
ccprovider.PutChaincodeToFS(pack) // errors: nil data bytes
// after
pack.data = parsed
datab, err := proto.Marshal(pack)
if err != nil { return err }
pack.datab = datab
ccprovider.PutChaincodeToFS(pack) Defensive patterns
Strategy: validation
Validate before calling
if pack != nil && pack.Data != nil && pack.Datab == nil {
return errors.New("package datab not serialized; marshal package first")
} Type guard
func hasSerializedBytes(p *ccprovider.SignedCDSPackage) bool {
return p != nil && p.Datab != nil && len(p.Datab) > 0
} Try / catch
err := ccprovider.PutChaincodeToFS(pack)
if err != nil {
if strings.Contains(err.Error(), "nil data bytes") {
datab, merr := proto.Marshal(pack)
if merr != nil { return merr }
pack.Datab = datab
return ccprovider.PutChaincodeToFS(pack)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Custom chaincode packaging tools, partial decoding of install packages after a Fabric upgrade, or tests that assemble package structs by hand.
Related errors
- env cannot be nil if buf and depspec are not nil
- nil data
- error writing chaincode install package to %s
- chaincode %s exists
- received nil proposal response
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/2341c3cbf0987db2.
Report an issue: GitHub.