{"record":{"id":"f0a66a4d7b094649","repo":"googleapis/mcp-toolbox","slug":"failed-to-list-buckets-in-project-q-w","errorCode":null,"errorMessage":"failed to list buckets in project %q: %w","messagePattern":"failed to list buckets in project %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudstorage/cloudstorage.go","lineNumber":303,"sourceCode":"// there are no more results).\nfunc (s *Source) ListBuckets(ctx context.Context, project, prefix string, maxResults int, pageToken string) (map[string]any, error) {\n\tif project == \"\" {\n\t\tproject = s.Project\n\t}\n\tit := s.client.Buckets(ctx, project)\n\tif prefix != \"\" {\n\t\tit.Prefix = prefix\n\t}\n\tps := maxResults\n\tif ps <= 0 {\n\t\tps = 1000\n\t}\n\tpager := iterator.NewPager(it, ps, pageToken)\n\n\tvar buckets []*storage.BucketAttrs\n\tnextPageToken, err := pager.NextPage(&buckets)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to list buckets in project %q: %w\", project, err)\n\t}\n\treturn map[string]any{\n\t\t\"buckets\":       buckets,\n\t\t\"nextPageToken\": nextPageToken,\n\t}, nil\n}\n\n// CreateBucket creates a Cloud Storage bucket and returns its freshly-read\n// metadata. When project is empty, the source's configured project is used.\n// When location is empty, Cloud Storage applies its service default.\nfunc (s *Source) CreateBucket(ctx context.Context, bucket, project, location string, uniformBucketLevelAccess bool) (map[string]any, error) {\n\tif err := s.validateBucket(bucket); err != nil {\n\t\treturn nil, err\n\t}\n\tif project == \"\" {\n\t\tproject = s.Project\n\t}\n\tattrs := &storage.BucketAttrs{Location: location}","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudstorage/cloudstorage.go#L285-L321","documentation":"The bucket paginator (iterator.NewPager / NextPage) failed while listing buckets in the GCP project; the source wraps the client error. The underlying error distinguishes auth/IAM failures (403), invalid project (404), and network problems.","triggerScenarios":"ListBuckets called with a project ID that doesn't exist or is misspelled, a caller lacking storage.buckets.list (resourcemanager projects need roles/storage.admin or at least browser access on the project), invalid pageToken, expired credentials, or network failure.","commonSituations":"Passing a project number or folder/org ID instead of the project ID; service account without project-level storage permissions; wrong project configured in credentials vs. the one queried; ADC not set up in the runtime environment.","solutions":["Verify the project ID string (not number, no domain suffix) exists via `gcloud projects list`.","Grant the caller's service account storage.buckets.list on the project (e.g. roles/storage.objectAdmin or Viewer at project level).","Ensure Application Default Credentials are set and valid for the target project (GOOGLE_APPLICATION_CREDENTIALS / gcloud auth application-default login).","Retry with backoff on transient network/5xx errors; regenerate an invalid pageToken by restarting the listing."],"exampleFix":"// before\nres, err := source.ListBuckets(ctx, \"123456789\", \"\", 100, \"\") // project number, not ID\n// after\nres, err := source.ListBuckets(ctx, \"my-actual-project-id\", \"\", 100, \"\")","handlingStrategy":"validation","validationCode":"// verify project id format: lowercase letters, digits, hyphens\nvar projectRe = regexp.MustCompile(`^[a-z][a-z0-9-]{4,28}[a-z0-9]$`)\nif !projectRe.MatchString(project) {\n    return fmt.Errorf(\"invalid GCP project id: %s\", project)\n}","typeGuard":null,"tryCatchPattern":"var e *apierror.APIError\nif errors.As(err, &e) {\n    switch e.HTTPCode() {\n    case 403: // missing storage.buckets.list IAM\n    case 404: // wrong project id\n    default: // transient: retry\n    }\n}","preventionTips":["Use the project ID (not number/org ID) exactly as shown by `gcloud projects list`.","Grant project-level storage view/admin roles to the service account.","Verify ADC credentials target the same project being queried.","Restart listing from an empty pageToken if a token error occurs."],"tags":["gcs","iam","project","list-buckets","cloudstorage"],"backgroundTag":"gcs-api-request-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"}