hyperledger/fabric · error

nil data

Error message

nil data

What it means

ValidateCC checks ccpack.data (the hashed CDSData) and returns 'nil data' when it is nil. Like the uninitialized depSpec check, this means the package was not fully initialized — the data hash computed by getCDSData is missing — so the package cannot be validated against ChaincodeData.

Source

Thrown at core/common/ccprovider/cdspackage.go:149

	// compute the id
	hash.Write(cdsdata.CodeHash)
	hash.Write(cdsdata.MetaDataHash)

	id := hash.Sum(nil)

	return b, id, cdsdata, nil
}

// ValidateCC returns error if the chaincode is not found or if its not a
// ChaincodeDeploymentSpec
func (ccpack *CDSPackage) ValidateCC(ccdata *ChaincodeData) error {
	if ccpack.depSpec == nil {
		return errors.New("uninitialized package")
	}

	if ccpack.data == nil {
		return errors.New("nil data")
	}

	// This is a hack. LSCC expects a specific LSCC error when names are invalid so it
	// has its own validation code. We can't use that error because of import cycles.
	// Unfortunately, we also need to check if what have makes some sort of sense as
	// protobuf will gladly deserialize garbage and there are paths where we assume that
	// a successful unmarshal means everything works but, if it fails, we try to unmarshal
	// into something different.
	if !isPrintable(ccdata.Name) {
		return fmt.Errorf("invalid chaincode name: %q", ccdata.Name)
	}

	if ccdata.Name != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Name || ccdata.Version != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Version {
		return fmt.Errorf("invalid chaincode data %v (%v)", ccdata, ccpack.depSpec.ChaincodeSpec.ChaincodeId)
	}

	otherdata := &CDSData{}
	err := proto.Unmarshal(ccdata.Data, otherdata)

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Initialize the package fully via InitFromBuffer or InitFromPath so getCDSData populates data
  2. Check the error from the initialization call before calling ValidateCC
  3. Do not manually set depSpec without running getCDSData / SetChaincodeData

Example fix

// before
ccpack.depSpec = depSpec // set directly, data left nil
ccpack.ValidateCC(ccdata)
// after
ccpack := &CDSPackage{}
ccpack.InitFromBuffer(buf) // populates depSpec, data, id
ccpack.ValidateCC(ccdata)
Defensive patterns

Strategy: validation

Validate before calling

// ensure full init so internal data hash is populated
if _, err := ccpack.InitFromBuffer(buf); err != nil {
    return fmt.Errorf("cannot validate: package data not initialized: %w", err)
}

Try / catch

if err := ccpack.ValidateCC(ccdata); err != nil {
    switch err.Error() {
    case "uninitialized package", "nil data":
        return fmt.Errorf("package not initialized before validation: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling ValidateCC on a CDSPackage where depSpec was set but data was never computed — e.g. partially constructed package, or a package whose getCDSData step was skipped/failed silently.

Common situations: Manually assembled CDSPackage in tests; partially completed initialization after a swallowed error; deserialization paths that set depSpec but not data.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/429481f86d612b09. Report an issue: GitHub.