{"record":{"id":"99257f6cc61b34f8","repo":"googleapis/mcp-toolbox","slug":"unable-to-read-query-results-w","errorCode":null,"errorMessage":"unable to read query results: %w","messagePattern":"unable to read query results: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/bigquery/bigquery.go","lineNumber":632,"sourceCode":"\t\tquery.ConnectionProperties = connProps\n\t}\n\tif labels != nil {\n\t\tquery.Labels = labels\n\t}\n\tif s.MaximumBytesBilled > 0 {\n\t\tquery.MaxBytesBilled = s.MaximumBytesBilled\n\t}\n\n\t// This block handles SELECT statements, which return a row set.\n\t// We iterate through the results, convert each row into a map of\n\t// column names to values, and return the collection of rows.\n\tjob, err := query.Run(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to execute query: %w\", err)\n\t}\n\tit, err := job.Read(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to read query results: %w\", err)\n\t}\n\n\tout := []any{}\n\tfor s.MaxQueryResultRows <= 0 || len(out) < s.MaxQueryResultRows {\n\t\tvar val []bigqueryapi.Value\n\t\terr = it.Next(&val)\n\t\tif err == iterator.Done {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to iterate through query results: %w\", err)\n\t\t}\n\t\tschema := it.Schema\n\t\trow := orderedmap.Row{}\n\t\tfor i, field := range schema {\n\t\t\trow.Add(field.Name, NormalizeValue(val[i]))\n\t\t}\n\t\tout = append(out, row)","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/bigquery/bigquery.go#L614-L650","documentation":"The query job was created successfully, but reading its results via job.Read(ctx) failed. This typically means the job did not complete successfully or the results are unavailable (failed/cancelled job, permission issue on the destination, or job metadata fetch error).","triggerScenarios":"query.Run succeeded but job.Read fails: the job failed asynchronously (validation errors detected at execution), the job was cancelled, the caller cannot read the job's results, or transient API errors when fetching the job's schema/status.","commonSituations":"Queries that pass creation but fail during execution (e.g. streaming buffer conflicts, resource limits), IAM granting job creation but not result read on shared job datasets, or transient 5xx from BigQuery.","solutions":["Inspect the wrapped error/job status to see why the job failed (Job.Status.ErrorResult) and fix the underlying query issue","Retry on transient errors (rate limit / 5xx) with exponential backoff","Ensure the caller can read results of jobs in the project/dataset (bigquery.jobs.get / dataViewer)","Check quotas (query slots, concurrent jobs) if the error indicates resource limits"],"exampleFix":"// before\nit, err := job.Read(ctx)\nif err != nil { return nil, err }\n// after\nit, err := job.Read(ctx)\nif err != nil {\n    if st := job.LastStatus(); st != nil && st.Err() != nil {\n        return nil, fmt.Errorf(\"job failed: %w\", st.Err())\n    }\n    return nil, backoff.Retry(func() error { _, err = job.Read(ctx); return err })\n}","handlingStrategy":"retry","validationCode":"if st := job.LastStatus(); st != nil && st.State != bigquery.JobDone && st.Err() != nil {\n    return st.Err() // job already failed; skip Read\n}","typeGuard":null,"tryCatchPattern":"_, err := src.RunSQL(ctx, client, stmt, \"SELECT\", params, nil, nil)\nif err != nil && strings.Contains(err.Error(), \"unable to read query results\") {\n    return backoff.RetryNotify(func() error {\n        _, err = src.RunSQL(ctx, client, stmt, \"SELECT\", params, nil, nil)\n        return err\n    }, expBackoff, nil)\n}","preventionTips":["Retry idempotent SELECT jobs on transient errors with backoff","Check Job.LastStatus().Err() to distinguish job failure from metadata fetch failure","Watch query quotas/slots to avoid jobs failing under load","Ensure read permissions on the project where the job runs"],"tags":["bigquery","job","query-results","transient"],"backgroundTag":"bigquery-job-read-failed","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"}