{"record":{"id":"45804d4ac7205d18","repo":"googleapis/mcp-toolbox","slug":"error-reading-start-of-json-array-w","errorCode":null,"errorMessage":"error reading start of json array: %w","messagePattern":"error reading start of json array: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics.go","lineNumber":303,"sourceCode":"\t\treturn \"\", fmt.Errorf(\"failed to send request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tbody, _ := io.ReadAll(resp.Body)\n\t\treturn \"\", fmt.Errorf(\"API returned non-200 status: %d %s\", resp.StatusCode, string(body))\n\t}\n\n\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 {","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics.go#L285-L321","documentation":"getStream streams the response as a JSON array and first reads the opening delimiter token with decoder.Token(). If that fails with anything other than io.EOF (io.EOF is treated as a valid empty response), this error is returned — meaning the response body was not a parseable JSON array.","triggerScenarios":"Invoke on the tool when the GDA endpoint returns a 200 response whose body is not a JSON array — e.g. an HTML error page from a proxy/load balancer, a truncated response, or an unexpected JSON object shape.","commonSituations":"Intercepting proxies or API gateways rewriting the response; responses cut off mid-stream (network interruption after headers); testing against a mock server that returns a JSON object instead of an array.","solutions":["Log the raw response body to inspect what was actually returned (proxy HTML, truncated JSON, etc.).","Check for proxies/gateways between the toolbox and the API that may rewrite or truncate responses.","Retry the request — transient stream truncation often resolves on retry.","If using a mock/test endpoint, make it return a JSON array of message objects."],"exampleFix":"// before: mock returns an object\n{\"messages\": []}\n// after: mock must return an array like the real API\n[{\"systemMessage\": {}}]","handlingStrategy":"retry","validationCode":"resp, err := client.Do(req)\nif err != nil { return err }\nct := resp.Header.Get(\"Content-Type\")\nif !strings.Contains(ct, \"json\") {\n    return fmt.Errorf(\"unexpected content-type %q; proxy may be rewriting response\", ct)\n}","typeGuard":null,"tryCatchPattern":"result, err := tool.Invoke(ctx, params)\nif err != nil && strings.Contains(err.Error(), \"error reading start of json array\") {\n    log.Printf(\"non-array response body; retrying: %v\", err)\n    return retryRequest(req)\n}","preventionTips":["Disable proxy/gateway response rewriting or buffering for this endpoint.","Retry transient stream failures with backoff.","Validate mock servers return a JSON array body."],"tags":["json","streaming","parsing","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"}