{"record":{"id":"b08939756ab50c98","repo":"googleapis/mcp-toolbox","slug":"failed-to-create-bigquery-client-for-project-q","errorCode":null,"errorMessage":"failed to create BigQuery client for project %q: %w","messagePattern":"failed to create BigQuery client for project %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/sources/bigquery/bigquery.go","lineNumber":818,"sourceCode":"\t\t}\n\t\ttokenSource = cred.TokenSource\n\t\topts = []option.ClientOption{\n\t\t\toption.WithUserAgent(userAgent),\n\t\t\toption.WithCredentials(cred),\n\t\t}\n\t}\n\n\tif endpoint != \"\" {\n\t\topts = append(opts, option.WithEndpoint(endpoint))\n\t}\n\tif quotaProject != \"\" {\n\t\topts = append(opts, option.WithQuotaProject(quotaProject))\n\t}\n\n\t// Initialize the high-level BigQuery client\n\tclient, err := bigqueryapi.NewClient(ctx, project, opts...)\n\tif err != nil {\n\t\treturn nil, nil, nil, fmt.Errorf(\"failed to create BigQuery client for project %q: %w\", project, err)\n\t}\n\tclient.Location = location\n\n\t// Initialize the low-level BigQuery REST service using the same credentials\n\trestService, err := bigqueryrestapi.NewService(ctx, opts...)\n\tif err != nil {\n\t\treturn nil, nil, nil, fmt.Errorf(\"failed to create BigQuery v2 service: %w\", err)\n\t}\n\n\treturn client, restService, tokenSource, nil\n}\n\n// initBigQueryConnectionWithOAuthToken initialize a BigQuery client with an\n// OAuth access token.\nfunc initBigQueryConnectionWithOAuthToken(\n\tctx context.Context,\n\ttracer trace.Tracer,\n\tproject string,","sourceCodeStart":800,"sourceCodeEnd":836,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/bigquery/bigquery.go#L800-L836","documentation":"This error is thrown when bigquery.NewClient (cloud.google.com/go/bigquery) fails to construct the high-level BigQuery client for the configured project, after credentials/token source resolution succeeded. The error wraps the underlying failure — usually an authentication option conflict, invalid client options, or an initial API/transport problem. The project ID is included for diagnosis.","triggerScenarios":"bigqueryapi.NewClient(ctx, project, opts...) fails with the assembled options (user agent, token source or credentials, quota project) — e.g. an invalid project ID, conflicting client options, or an inability to reach the BigQuery API endpoint during client initialization.","commonSituations":"Typo or nonexistent project ID in the source config; quota project misconfigured; running where googleapis.com is blocked by a firewall/proxy; invalid combined credentials (both token source and credentials set incorrectly by a code change); wrong location/project pairing.","solutions":["Verify the project ID in the source config exists and is spelled correctly (gcloud projects describe <id>).","Confirm network/proxy access to bigquery.googleapis.com.","Check that the configured quota project is valid and the caller has access to it.","Inspect the wrapped error with errors.As (googleapi.Error) for precise HTTP status and message.","Confirm credentials resolved earlier are valid for the project (bq ls --project_id=<id>)."],"exampleFix":"// before (my-sdk.yaml)\nsources:\n  my-bq:\n    kind: bigquery\n    project: my-projekt  // typo\n// after\nsources:\n  my-bq:\n    kind: bigquery\n    project: my-project","handlingStrategy":"validation","validationCode":"// Verify project and connectivity before client creation\nproject := \"my-project\"\nout, err := exec.Command(\"gcloud\", \"projects\", \"describe\", project, \"--format=value(projectId)\").CombinedOutput()\nif err != nil {\n  return fmt.Errorf(\"project %q invalid or inaccessible: %v: %s\", project, err, out)\n}\n// And a smoke test that credentials + project work:\n// bq ls --project_id=%s --max_results=1","typeGuard":null,"tryCatchPattern":"// Go\nclient, rest, ts, err := initBigQueryConnection(ctx, cfg)\nif err != nil && strings.Contains(err.Error(), \"failed to create BigQuery client\") {\n  var gerr *googleapi.Error\n  if errors.As(err, &gerr) {\n    log.Fatalf(\"BigQuery client creation failed (HTTP %d): %v\", gerr.Code, gerr)\n  }\n  log.Fatalf(\"BigQuery client creation failed: %v — check project id, network, and quota project\", err)\n}","preventionTips":["Verify the project ID with 'gcloud projects describe' before configuring.","Ensure outbound access to bigquery.googleapis.com (proxy/firewall).","Validate the quota project setting and access to it.","Run a smoke test (bq ls) using the same credentials at startup."],"tags":["bigquery","gcp","client-initialization","network","project-config"],"backgroundTag":"bigquery-client-creation-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"}