{"record":{"id":"f53e8d44b16879df","repo":"googleapis/mcp-toolbox","slug":"failed-to-get-metadata-for-created-bucket-q-w","errorCode":null,"errorMessage":"failed to get metadata for created bucket %q: %w","messagePattern":"failed to get metadata for created bucket %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/sources/cloudstorage/cloudstorage.go","lineNumber":333,"sourceCode":"\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}\n\tif uniformBucketLevelAccess {\n\t\tattrs.UniformBucketLevelAccess = storage.UniformBucketLevelAccess{Enabled: true}\n\t}\n\n\tbkt := s.client.Bucket(bucket)\n\tif err := bkt.Create(ctx, project, attrs); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create bucket %q in project %q: %w\", bucket, project, err)\n\t}\n\n\tcreatedAttrs, err := bkt.Attrs(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get metadata for created bucket %q: %w\", bucket, err)\n\t}\n\treturn map[string]any{\n\t\t\"bucket\":   bucket,\n\t\t\"created\":  true,\n\t\t\"metadata\": createdAttrs,\n\t}, nil\n}\n\n// GetBucketMetadata returns raw bucket metadata from the Cloud Storage client.\nfunc (s *Source) GetBucketMetadata(ctx context.Context, bucket string) (*storage.BucketAttrs, error) {\n\tif err := s.validateBucket(bucket); err != nil {\n\t\treturn nil, err\n\t}\n\tattrs, err := s.client.Bucket(bucket).Attrs(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get metadata for bucket %q: %w\", bucket, err)\n\t}\n\treturn attrs, nil","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudstorage/cloudstorage.go#L315-L351","documentation":"The bucket was created successfully, but the follow-up BucketHandle.Attrs call to fetch its metadata failed. The resource exists; only the read-back of attributes (wrapped error: IAM, transient network, or eventual consistency) failed.","triggerScenarios":"CreateBucket succeeded, then bkt.Attrs(ctx) failed immediately after: transient 5xx/network blip, context cancelled, or the caller lacking storage.buckets.get despite having create rights, or replication lag on fresh buckets.","commonSituations":"Short client timeouts firing right after the create RPC; service accounts with create-but-not-get IAM splits (unusual custom roles); reading metadata of a bucket created milliseconds earlier.","solutions":["Retry with backoff: the bucket exists, so re-fetch metadata via a separate Attrs/GetGoogleCloudbucket call.","Grant the service account storage.buckets.get in addition to create if using a custom role.","Extend the context timeout so the metadata read isn't cancelled immediately after creation.","Treat the operation as partially successful: verify with gsutil/gcloud whether the bucket exists before re-creating."],"exampleFix":"// before\ncreated, err := source.CreateBucket(ctx, name, proj, nil, \"US\", \"STANDARD\", true) // attrs read failed\n// after (recover)\nif err != nil {\n    time.Sleep(500 * time.Millisecond)\n    created, err = source.CreateBucket(ctx, name, proj, nil, \"US\", \"STANDARD\", true) // or re-fetch attrs\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt := 0; attempt < 3; attempt++ {\n    res, err := source.CreateBucket(ctx, name, proj, nil, loc, class, ula)\n    if err == nil { break }\n    time.Sleep(time.Duration(1<<attempt) * 200 * time.Millisecond) // bucket already exists; retry gets metadata\n}","preventionTips":["Retry the operation with backoff - the bucket exists and re-running is safe until metadata reads succeed.","Give the service account storage.buckets.get alongside create.","Use a context timeout long enough to cover create + metadata read.","Log this as a partial success and reconcile via a metadata check before recreating."],"tags":["gcs","metadata","retry","bucket-creation","cloudstorage"],"backgroundTag":"metadata-fetch-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"}