hyperledger/fabric · error

error unmarshalling chaincode collection config pkg

Error message

error unmarshalling chaincode collection config pkg

What it means

Raised by fetchCollConfigPkg in lscc when the collection configuration package bytes stored in the lscc namespace fail to proto-unmarshal into peer.CollectionConfigPackage. The stored collection config for the chaincode is corrupt or in an unexpected format, so collection configuration cannot be returned.

Source

Thrown at core/scc/lscc/deployedcc_infoprovider.go:153

	}
	for _, conf := range collConfigPkg.Config {
		staticCollConfig := conf.GetStaticCollectionConfig()
		if staticCollConfig != nil && staticCollConfig.Name == collectionName {
			return staticCollConfig, nil
		}
	}
	return nil, nil
}

func fetchCollConfigPkg(chaincodeName string, qe ledger.SimpleQueryExecutor) (*peer.CollectionConfigPackage, error) {
	collKey := privdata.BuildCollectionKVSKey(chaincodeName)
	collectionConfigPkgBytes, err := qe.GetState(lsccNamespace, collKey)
	if err != nil || collectionConfigPkgBytes == nil {
		return nil, err
	}
	collectionConfigPkg := &peer.CollectionConfigPackage{}
	if err := proto.Unmarshal(collectionConfigPkgBytes, collectionConfigPkg); err != nil {
		return nil, errors.Wrap(err, "error unmarshalling chaincode collection config pkg")
	}
	return collectionConfigPkg, nil
}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Inspect the wrapped proto error to confirm which field/encoding failed
  2. Re-define the chaincode's collections config so a valid CollectionConfigPackage is written to lscc state
  3. Restore the state database from a consistent backup
  4. Verify no external process wrote raw/non-proto bytes under the lscc coll key
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: pre-check collection config bytes decode
collKey := buildCollectionConfigKey(chaincodeName)
raw, err := qe.GetState("lscc", collKey)
if err != nil { return err }
if raw != nil {
    pkg := &peer.CollectionConfigPackage{}
    if err := proto.Unmarshal(raw, pkg); err != nil {
        return fmt.Errorf("corrupt collection config for %s: %w", chaincodeName, err)
    }
}

Try / catch

// Go
pkg, err := fetchCollConfigPkg(chaincodeName, qe)
if err != nil {
    if strings.Contains(err.Error(), "unmarshalling chaincode collection config") {
        return fmt.Errorf("corrupt collection config package for %s: %w", chaincodeName, err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling ChaincodeInfo, AllCollectionsConfigPkg, or CollectionInfo when GetState(lsccNamespace, collKey) returns bytes that fail proto.Unmarshal into CollectionConfigPackage.

Common situations: Corrupted collection config records in the ledger; state written by a different Fabric release with an incompatible CollectionConfigPackage encoding; manual ledger edits or a bad restore.

Understand the failure class

Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.

Related errors


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