hyperledger/fabric · error
not a chaincode type: %s
Error message
not a chaincode type: %s
What it means
Thrown by ChaincodeDefinitionIfDefined when the namespace metadata found in the lifecycle state has a Datatype other than ChaincodeDefinitionType, meaning the requested name exists in the lifecycle namespace but is not a chaincode definition (e.g. it is a collection or other namespace entry).
Source
Thrown at core/chaincode/lifecycle/lifecycle.go:262
return true, &ChaincodeDefinition{
EndorsementInfo: &lb.ChaincodeEndorsementInfo{
InitRequired: false,
},
ValidationInfo: &lb.ChaincodeValidationInfo{},
}, nil
}
metadata, ok, err := r.Serializer.DeserializeMetadata(NamespacesName, chaincodeName, state)
if err != nil {
return false, nil, errors.WithMessagef(err, "could not deserialize metadata for chaincode %s", chaincodeName)
}
if !ok {
return false, nil, nil
}
if metadata.Datatype != ChaincodeDefinitionType {
return false, nil, errors.Errorf("not a chaincode type: %s", metadata.Datatype)
}
definedChaincode := &ChaincodeDefinition{}
err = r.Serializer.Deserialize(NamespacesName, chaincodeName, metadata, definedChaincode, state)
if err != nil {
return false, nil, errors.WithMessagef(err, "could not deserialize chaincode definition for chaincode %s", chaincodeName)
}
return true, definedChaincode, nil
}
func (r *Resources) LifecycleEndorsementPolicyAsBytes(channelID string) ([]byte, error) {
channelConfig := r.ChannelConfigSource.GetStableChannelConfig(channelID)
if channelConfig == nil {
return nil, errors.Errorf("could not get channel config for channel '%s'", channelID)
}
if _, ok := channelConfig.PolicyManager().GetPolicy(LifecycleEndorsementPolicyRef); ok {View on GitHub (pinned to 2736b63f8f)
Solutions
- Verify the chaincode name is correct and actually approved/committed as a chaincode
- Use 'peer lifecycle chaincode querycommitted' to list real committed chaincodes on the channel
- Check the peer's lifecycle state (couchdb/leveldb) for corruption if the name should be a chaincode
Example fix
// before ChaincodeInfo(channel: 'ch1', name: 'mycc_private_collection') // not a chaincode type // after ChaincodeInfo(channel: 'ch1', name: 'mycc') // use the chaincode name, not the collection name
Defensive patterns
Strategy: type-guard
Validate before calling
ok, metadata, err := lifecycleQueryNamespaceMetadata(chname, ccname, state)
if err != nil { return err }
if ok && metadata.Datatype != lifecycle.ChaincodeDefinitionType {
return fmt.Errorf("%s is not a chaincode namespace", ccname)
} Type guard
func isChaincodeDefinition(metadata *lb.StateMetadata) bool {
return metadata != nil && metadata.Datatype == lifecycle.ChaincodeDefinitionType
} Try / catch
_, def, err := resources.ChaincodeDefinitionIfDefined(ccname)
if err != nil {
if strings.Contains(err.Error(), "not a chaincode type") {
// wrong namespace: check whether ccname is a collection or other entry
}
return err
} Prevention
- Only query chaincode definitions with actual chaincode names, not collection names
- List committed chaincodes with querycommitted before querying a definition
- Never hand-edit lifecycle state storage on peers
When it happens
Trigger: Calling QueryChaincodeDefinition / ChaincodeInfo / CollectionInfo / ValidationInfo / ImplicitCollections for a name that maps to a non-chaincode metadata type in the lifecycle state store.
Common situations: Querying a private collection name as if it were a chaincode; typos in the chaincode name colliding with another namespace entry; corrupted or hand-edited lifecycle state on the peer.
Related errors
- failed listing installed chaincodes
- failed to parse collection config
- [channel %s] failed to get chaincode container info for %s
- chaincode '%s' does not require initialization but called as
- private data APIs are not allowed in chaincode Init()
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/011f0f137ca7def2.
Report an issue: GitHub.