googleapis/mcp-toolbox · error
unable to read query results: %w
Error message
unable to read query results: %w
What it means
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).
Source
Thrown at internal/sources/bigquery/bigquery.go:632
query.ConnectionProperties = connProps
}
if labels != nil {
query.Labels = labels
}
if s.MaximumBytesBilled > 0 {
query.MaxBytesBilled = s.MaximumBytesBilled
}
// This block handles SELECT statements, which return a row set.
// We iterate through the results, convert each row into a map of
// column names to values, and return the collection of rows.
job, err := query.Run(ctx)
if err != nil {
return nil, fmt.Errorf("unable to execute query: %w", err)
}
it, err := job.Read(ctx)
if err != nil {
return nil, fmt.Errorf("unable to read query results: %w", err)
}
out := []any{}
for s.MaxQueryResultRows <= 0 || len(out) < s.MaxQueryResultRows {
var val []bigqueryapi.Value
err = it.Next(&val)
if err == iterator.Done {
break
}
if err != nil {
return nil, fmt.Errorf("unable to iterate through query results: %w", err)
}
schema := it.Schema
row := orderedmap.Row{}
for i, field := range schema {
row.Add(field.Name, NormalizeValue(val[i]))
}
out = append(out, row)View on GitHub (pinned to 8cc6e09de2)
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
Example fix
// before
it, err := job.Read(ctx)
if err != nil { return nil, err }
// after
it, err := job.Read(ctx)
if err != nil {
if st := job.LastStatus(); st != nil && st.Err() != nil {
return nil, fmt.Errorf("job failed: %w", st.Err())
}
return nil, backoff.Retry(func() error { _, err = job.Read(ctx); return err })
} Defensive patterns
Strategy: retry
Validate before calling
if st := job.LastStatus(); st != nil && st.State != bigquery.JobDone && st.Err() != nil {
return st.Err() // job already failed; skip Read
} Try / catch
_, err := src.RunSQL(ctx, client, stmt, "SELECT", params, nil, nil)
if err != nil && strings.Contains(err.Error(), "unable to read query results") {
return backoff.RetryNotify(func() error {
_, err = src.RunSQL(ctx, client, stmt, "SELECT", params, nil, nil)
return err
}, expBackoff, nil)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- cannot unmarshal %T into StringOrStringSlice
- invalid writeMode %q: must be one of %q, %q, or %q
- conflicting source configuration: readOnly is %v, but writeM
- writeMode 'protected' cannot be used with useClientOAuth ena
- useClientOAuth cannot be used with impersonateServiceAccount
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/99257f6cc61b34f8.
Report an issue: GitHub.