{"record":{"id":"dfe82f2f2c38b9f9","repo":"googleapis/mcp-toolbox","slug":"failed-to-list-objects-in-bucket-q-w","errorCode":null,"errorMessage":"failed to list objects in bucket %q: %w","messagePattern":"failed to list objects in bucket %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudstorage/cloudstorage.go","lineNumber":215,"sourceCode":"\tif err := s.validateBucket(bucket); err != nil {\n\t\treturn nil, err\n\t}\n\tit := s.client.Bucket(bucket).Objects(ctx, &storage.Query{\n\t\tPrefix:    prefix,\n\t\tDelimiter: delimiter,\n\t})\n\t// iterator.NewPager errors on pageSize <= 0; the tool layer already rejects\n\t// values above the GCS per-page cap of 1000, so any positive value is safe.\n\tps := maxResults\n\tif ps <= 0 {\n\t\tps = 1000\n\t}\n\tpager := iterator.NewPager(it, ps, pageToken)\n\n\tvar attrsPage []*storage.ObjectAttrs\n\tnextPageToken, err := pager.NextPage(&attrsPage)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to list objects in bucket %q: %w\", bucket, err)\n\t}\n\n\tobjects := make([]*storage.ObjectAttrs, 0, len(attrsPage))\n\tprefixes := make([]string, 0)\n\tfor _, attrs := range attrsPage {\n\t\tif attrs.Prefix != \"\" {\n\t\t\tprefixes = append(prefixes, attrs.Prefix)\n\t\t\tcontinue\n\t\t}\n\t\tobjects = append(objects, attrs)\n\t}\n\n\treturn map[string]any{\n\t\t\"objects\":       objects,\n\t\t\"prefixes\":      prefixes,\n\t\t\"nextPageToken\": nextPageToken,\n\t}, nil\n}","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudstorage/cloudstorage.go#L197-L233","documentation":"The GCS paginator (iterator.NewPager / NextPage) returned an error while listing objects in the bucket, and the source wraps it with this message. The underlying %w error carries the actual cause: an HTTP/gRPC failure from the Cloud Storage API, an auth problem, or a missing bucket.","triggerScenarios":"Calling ListObjects with a pageToken/page size where pager.NextPage fails: bucket does not exist (404), caller lacks storage.objects.list IAM permission (403), unauthenticated/expired credentials, network unreachable, or an invalid continuation pageToken.","commonSituations":"Deleted or misspelled bucket name; service account without roles/storage.objectViewer on the bucket; Application Default Credentials not set (GOOGLE_APPLICATION_CREDENTIALS unset); running behind a proxy/firewall blocking storage.googleapis.com.","solutions":["Inspect the wrapped error: fix the bucket name or create the bucket if it is a 404.","Grant the service account storage.objects.list (e.g. roles/storage.objectViewer) on the bucket.","Verify credentials are configured (gcloud auth application-default login or GOOGLE_APPLICATION_CREDENTIALS) and not expired.","Fix network/proxy reachability to storage.googleapis.com, then retry with backoff on transient errors."],"exampleFix":"// before\nres, err := source.ListObjects(ctx, \"my-proj-bucket\", \"\", 100, \"\")\n// after (validate access first)\nif _, err := source.ListBuckets(ctx, \"my-project\", \"\", 1); err != nil {\n    // fix credentials/IAM before retrying ListObjects\n}\nres, err := source.ListObjects(ctx, \"my-proj-bucket\", \"\", 100, \"\")","handlingStrategy":"retry","validationCode":"// verify auth + project access first\ncreds := os.Getenv(\"GOOGLE_APPLICATION_CREDENTIALS\")\nif creds == \"\" && os.Getenv(\"GOOGLE_CLOUD_PROJECT\") == \"\" {\n    return errors.New(\"no GCP credentials configured\")\n}","typeGuard":null,"tryCatchPattern":"var e *apierror.APIError\nif errors.As(err, &e) {\n    switch e.HTTPCode() {\n    case 404: // wrong bucket name\n    case 403: // fix IAM\n    default: // transient: retry with backoff\n    }\n}","preventionTips":["Validate bucket names against ListBuckets output before listing objects.","Grant service accounts explicit objectViewer roles on buckets.","Set up Application Default Credentials in every runtime environment.","Implement exponential backoff for transient 5xx/network errors."],"tags":["gcs","network","iam","list-objects","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"}