{"record":{"id":"aed2d4cf671e1f42","repo":"hyperledger/fabric","slug":"unmarshalling-chaincodequeryresponse-failed","errorCode":null,"errorMessage":"unmarshalling ChaincodeQueryResponse failed","messagePattern":"unmarshalling ChaincodeQueryResponse failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/committer/txvalidator/v14/vscc_validator.go","lineNumber":314,"sourceCode":"\t\treturn nil, errors.WithMessage(err, \"could not retrieve QueryExecutor\")\n\t}\n\tdefer qe.Done()\n\n\tbytes, err := qe.GetState(\"lscc\", ccid)\n\tif err != nil {\n\t\treturn nil, &commonerrors.VSCCInfoLookupFailureError{\n\t\t\tReason: fmt.Sprintf(\"Could not retrieve state for chaincode %s, error %s\", ccid, err),\n\t\t}\n\t}\n\n\tif bytes == nil {\n\t\treturn nil, errors.Errorf(\"lscc's state for [%s] not found.\", ccid)\n\t}\n\n\tcd := &ccprovider.ChaincodeData{}\n\terr = proto.Unmarshal(bytes, cd)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"unmarshalling ChaincodeQueryResponse failed\")\n\t}\n\n\tif cd.Vscc == \"\" {\n\t\treturn nil, errors.Errorf(\"lscc's state for [%s] is invalid, vscc field must be set\", ccid)\n\t}\n\n\tif len(cd.Policy) == 0 {\n\t\treturn nil, errors.Errorf(\"lscc's state for [%s] is invalid, policy field must be set\", ccid)\n\t}\n\n\treturn cd, err\n}\n\n// GetInfoForValidate gets the ChaincodeInstance(with latest version) of tx, vscc and policy from lscc\nfunc (v *VsccValidatorImpl) GetInfoForValidate(chdr *common.ChannelHeader, ccID string) (*sysccprovider.ChaincodeInstance, *sysccprovider.ChaincodeInstance, []byte, error) {\n\tcc := &sysccprovider.ChaincodeInstance{\n\t\tChannelID:     chdr.ChannelId,\n\t\tChaincodeName: ccID,","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/committer/txvalidator/v14/vscc_validator.go#L296-L332","documentation":"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.","triggerScenarios":"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.","commonSituations":"State database corruption or manual edits to lscc keys; chaincode data written by an incompatible Fabric version; ledger migration issues after upgrading peers.","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"],"exampleFix":"// before: migrating ledger with mismatched peer versions\npeer upgraded from 1.2 to 2.2 directly over old state\n// after: re-instantiate after upgrade\npeer chaincode upgrade -C mychannel -n mycc -v 2.0","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await tx.validate(); } catch (e) {\n  if (String(e).includes('unmarshalling ChaincodeQueryResponse')) { /* rebuild state DB or re-instantiate chaincode */ }\n}","preventionTips":["Never edit lscc state manually","Keep peer versions consistent across upgrades","Re-instantiate chaincodes after ledger migrations"],"tags":["hyperledger-fabric","lscc","protobuf","unmarshal","state-corruption"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}