{"record":{"id":"8e1169dbb316a05e","repo":"googleapis/mcp-toolbox","slug":"error-decoding-raw-message-w","errorCode":null,"errorMessage":"error decoding raw message: %w","messagePattern":"error decoding raw message: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics.go","lineNumber":312,"sourceCode":"\tvar messages []map[string]any\n\tdecoder := json.NewDecoder(resp.Body)\n\tdataMsgIdx := -1\n\n\t// The response is a JSON array, so we read the opening bracket.\n\tif _, err := decoder.Token(); err != nil {\n\t\tif err == io.EOF {\n\t\t\treturn \"\", nil // Empty response is valid\n\t\t}\n\t\treturn \"\", fmt.Errorf(\"error reading start of json array: %w\", err)\n\t}\n\n\tfor decoder.More() {\n\t\tvar rawMsg json.RawMessage\n\t\tif err := decoder.Decode(&rawMsg); err != nil {\n\t\t\tif err == io.EOF {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\treturn \"\", fmt.Errorf(\"error decoding raw message: %w\", err)\n\t\t}\n\n\t\tvar msg map[string]any\n\t\tif err := json.Unmarshal(rawMsg, &msg); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"error unmarshaling raw message: %w\", err)\n\t\t}\n\n\t\tvar processedMsg map[string]any\n\t\tif dataResult := extractDataResult(msg); dataResult != nil {\n\t\t\t// 1. If it's a data result, format it.\n\t\t\tprocessedMsg = formatDataRetrieved(dataResult, maxRows)\n\t\t\tif dataMsgIdx >= 0 {\n\t\t\t\t// Replace previous data with a placeholder. Intermediate data results in a\n\t\t\t\t// stream are redundant and consume unnecessary tokens.\n\t\t\t\tmessages[dataMsgIdx] = map[string]any{\"Data Retrieved\": \"Intermediate result omitted\"}\n\t\t\t}\n\t\t\tdataMsgIdx = len(messages)\n\t\t} else if sm, ok := msg[\"systemMessage\"].(map[string]any); ok {","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics.go#L294-L330","documentation":"While iterating the JSON array with decoder.More(), each element is decoded into a json.RawMessage. If a decode step fails for a reason other than clean EOF (malformed JSON mid-stream, invalid UTF-8, truncated element), this wrapped error is returned.","triggerScenarios":"Invoke on the tool when the streamed GDA response contains a corrupt or truncated JSON element inside the array — typically from a dropped connection mid-stream or a malformed element produced by the API/proxy.","commonSituations":"Unstable network dropping the connection mid-response; aggressive idle timeouts on load balancers killing long streams; proxy buffering limits truncating the body.","solutions":["Retry the request; mid-stream corruption is usually transient network/load-balancer behavior.","Increase idle/read timeouts on proxies and load balancers in front of the toolbox to keep long streaming responses alive.","Check proxy buffering settings (e.g. disable response buffering for streaming endpoints).","Log the partial raw message around the failure to identify where truncation occurs."],"exampleFix":"// before: nginx default proxy_read_timeout 60s kills long streams\n// after\n//   proxy_read_timeout 600s;\n//   proxy_buffering off;","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"result, err := tool.Invoke(ctx, params)\nif err != nil && strings.Contains(err.Error(), \"error decoding raw message\") {\n    // mid-stream truncation: safe to retry, request had no side effects beyond read\n    return retryWithBackoff(req, 3)\n}","preventionTips":["Raise proxy_read_timeout / LB idle timeouts for streaming endpoints.","Disable response buffering on reverse proxies.","Prefer stable networks/regions between the toolbox and the API.","Log partial bodies to detect recurring truncation points."],"tags":["json","streaming","network","bigquery"],"backgroundTag":"invalid-json-response","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}