hyperledger/fabric · error
unmarshalling ChaincodeQueryResponse failed
Error message
unmarshalling ChaincodeQueryResponse failed
What it means
After retrieving the chaincode's bytes from lscc state, getCDataForCC unmarshals them into ChaincodeData. If proto.Unmarshal fails, the stored state is not a valid ChaincodeQueryResponse/ChaincodeData, and the error is wrapped as 'unmarshalling ChaincodeQueryResponse failed'. This indicates corrupted or malformed lscc records.
Source
Thrown at core/committer/txvalidator/v14/vscc_validator.go:314
return nil, errors.WithMessage(err, "could not retrieve QueryExecutor")
}
defer qe.Done()
bytes, err := qe.GetState("lscc", ccid)
if err != nil {
return nil, &commonerrors.VSCCInfoLookupFailureError{
Reason: fmt.Sprintf("Could not retrieve state for chaincode %s, error %s", ccid, err),
}
}
if bytes == nil {
return nil, errors.Errorf("lscc's state for [%s] not found.", ccid)
}
cd := &ccprovider.ChaincodeData{}
err = proto.Unmarshal(bytes, cd)
if err != nil {
return nil, errors.Wrap(err, "unmarshalling ChaincodeQueryResponse failed")
}
if cd.Vscc == "" {
return nil, errors.Errorf("lscc's state for [%s] is invalid, vscc field must be set", ccid)
}
if len(cd.Policy) == 0 {
return nil, errors.Errorf("lscc's state for [%s] is invalid, policy field must be set", ccid)
}
return cd, err
}
// GetInfoForValidate gets the ChaincodeInstance(with latest version) of tx, vscc and policy from lscc
func (v *VsccValidatorImpl) GetInfoForValidate(chdr *common.ChannelHeader, ccID string) (*sysccprovider.ChaincodeInstance, *sysccprovider.ChaincodeInstance, []byte, error) {
cc := &sysccprovider.ChaincodeInstance{
ChannelID: chdr.ChannelId,
ChaincodeName: ccID,View on GitHub (pinned to 2736b63f8f)
Solutions
- Rebuild or repair the state database for the affected channel
- Re-instantiate/upgrade the chaincode so lscc rewrites a valid ChaincodeData record
- Check Fabric version consistency across peers and any ledger migrations performed
- Inspect the raw lscc value to identify what wrote the malformed record
Example fix
// before: migrating ledger with mismatched peer versions peer upgraded from 1.2 to 2.2 directly over old state // after: re-instantiate after upgrade peer chaincode upgrade -C mychannel -n mycc -v 2.0
Defensive patterns
Strategy: try-catch
Try / catch
try { await tx.validate(); } catch (e) {
if (String(e).includes('unmarshalling ChaincodeQueryResponse')) { /* rebuild state DB or re-instantiate chaincode */ }
} Prevention
- Never edit lscc state manually
- Keep peer versions consistent across upgrades
- Re-instantiate chaincodes after ledger migrations
When it happens
Trigger: lscc state for ccid exists (bytes non-nil) but is not valid protobuf ChaincodeData — corruption, wrong bytes written to the lscc namespace, or format changes between versions.
Common situations: State database corruption or manual edits to lscc keys; chaincode data written by an incompatible Fabric version; ledger migration issues after upgrading peers.
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
- failed to deserialize values
- error converting envelope to config update: %s
- failed unmarshalling lscc read value into ChaincodeData
- failed to unmarshal response for transaction %s
- could not unmarshal chaincode package to CDS or SignedCDS
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/aed2d4cf671e1f42.
Report an issue: GitHub.