{"record":{"id":"57c6d15505b7fe80","repo":"hyperledger/fabric","slug":"server-returned-response-of-unexpected-type-v","errorCode":null,"errorMessage":"server returned response of unexpected type: %v","messagePattern":"server returned response of unexpected type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"discovery/cmd/endorsers.go","lineNumber":136,"sourceCode":"// EndorserResponseParser parses endorsement responses from the peer\ntype EndorserResponseParser struct {\n\tio.Writer\n}\n\n// ParseResponse parses the given response for the given channel\nfunc (parser *EndorserResponseParser) ParseResponse(channel string, res ServiceResponse) error {\n\trawResponse := res.Raw()\n\tif len(rawResponse.Results) == 0 {\n\t\treturn errors.New(\"empty results\")\n\t}\n\n\tif e := rawResponse.Results[0].GetError(); e != nil {\n\t\treturn errors.Errorf(\"server returned: %s\", e.Content)\n\t}\n\n\tccQueryRes := rawResponse.Results[0].GetCcQueryRes()\n\tif ccQueryRes == nil {\n\t\treturn errors.Errorf(\"server returned response of unexpected type: %v\", reflect.TypeFor[*discovery.QueryResult]())\n\t}\n\n\tjsonBytes, _ := json.MarshalIndent(parseEndorsementDescriptors(ccQueryRes.Content), \"\", \"\\t\")\n\tfmt.Fprintln(parser.Writer, string(jsonBytes))\n\treturn nil\n}\n\ntype chaincodesAndCollections struct {\n\tChaincodes  *[]string\n\tCollections *map[string]string\n\tNoPrivReads *[]string\n}\n\nfunc (ec *chaincodesAndCollections) noPrivateReads(chaincodeName string) bool {\n\treturn slices.Contains(*ec.NoPrivReads, chaincodeName)\n}\n\nfunc (ec *chaincodesAndCollections) existsInChaincodes(chaincodeName string) bool {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/discovery/cmd/endorsers.go#L118-L154","documentation":"ParseResponse expects Results[0] to be a chaincode query result (GetCcQueryRes). If that field is nil — the server returned some other QueryResult type (config, membership, or nil) — the parser rejects it with \"server returned response of unexpected type\". This is a type-mismatch guard ensuring the response matches the endorsers query that was sent.","triggerScenarios":"Sending an endorsers request but receiving a response whose first result is a config query result, membership result, or an unset/nil result — usually from mismatched request/response pairing or a server/client version mismatch.","commonSituations":"Reusing a response object from a different query type (config/membership) with the endorsers parser; peer version returning a different result schema; mixing discovery client versions between CLI and peer.","solutions":["Ensure ParseResponse is called on the response of an AddEndorsersQuery request, not a config/membership query","Align peer and discovery client/CLI versions","Inspect the raw response (res.Raw()) to see what result type was actually returned"],"exampleFix":"// before\nres, _ := stub.Send(server, conf, configReq)\nparser.ParseResponse(channel, res) // config response parsed as endorsers\n// after\nres, _ := stub.Send(server, conf, endorsersReq)\nparser.ParseResponse(channel, res)","handlingStrategy":"type-guard","validationCode":"raw := res.Raw()\nif len(raw.Results) > 0 && raw.Results[0].GetCcQueryRes() == nil {\n    return errors.New(\"response is not a chaincode query result; was this response from an endorsers query?\")\n}","typeGuard":"func isEndorsersResponse(res discovery.ServiceResponse) bool {\n    raw := res.Raw()\n    return len(raw.Results) > 0 && raw.Results[0].GetCcQueryRes() != nil\n}","tryCatchPattern":"if err := parser.ParseResponse(channel, res); err != nil {\n    if strings.Contains(err.Error(), \"unexpected type\") {\n        return fmt.Errorf(\"response/query mismatch: ensure ParseResponse is paired with AddEndorsersQuery: %w\", err)\n    }\n    return err\n}","preventionTips":["Pair each response with the parser matching its query type (endorsers vs config vs membership)","Keep one discovery client version across CLI and application code","Assert the query type before parsing with GetCcQueryRes != nil"],"tags":["go","discovery","response-parsing","type-mismatch"],"backgroundTag":"unexpected-response-type","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"}