{"record":{"id":"138ff1e5f781ec7a","repo":"googleapis/mcp-toolbox","slug":"failed-to-create-bucket-q-in-project-q-w","errorCode":null,"errorMessage":"failed to create bucket %q in project %q: %w","messagePattern":"failed to create bucket %q in project %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudstorage/cloudstorage.go","lineNumber":328,"sourceCode":"\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}\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}","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudstorage/cloudstorage.go#L310-L346","documentation":"BucketHandle.Create failed while creating the bucket in the given project. The wrapped GCS error explains the cause: most often the (globally unique) bucket name is already taken, the name is invalid, or the caller lacks storage.buckets.create permission.","triggerScenarios":"CreateBucket called with a bucket name already used anywhere in GCS (409 conflict), a name violating bucket naming rules, a caller whose service account lacks storage.buckets.create, or invalid attrs (bad location/storage class).","commonSituations":"Retrying a create after a previous partial run (name now exists); picking common names like 'my-test-bucket' that are globally taken; creating in a project without the Cloud Storage API enabled; org policy forbidding certain locations.","solutions":["Check for 409 AlreadyExists: if the bucket exists and is yours, skip creation and proceed to Attrs/usage.","Generate a globally unique, lowercase, hyphenated name (e.g. project-scoped with random suffix).","Grant the service account roles/storage.admin (or storage.buckets.create) on the project and enable the Cloud Storage API.","Validate the requested location/storage class against org policy before retrying."],"exampleFix":"// before\nsource.CreateBucket(ctx, \"my-test-bucket\", \"my-project\", nil, \"US\", \"STANDARD\", false) // name taken\n// after\nname := fmt.Sprintf(\"my-project-bucket-%s\", strings.ToLower(uniqSuffix()))\nsource.CreateBucket(ctx, name, \"my-project\", nil, \"US\", \"STANDARD\", false)","handlingStrategy":"try-catch","validationCode":"// bucket names: 3-63 lowercase letters, digits, hyphens, dots\nvar bucketNameRe = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]{1,61}[a-z0-9]$`)\nif !bucketNameRe.MatchString(bucket) {\n    return fmt.Errorf(\"invalid bucket name: %s\", bucket)\n}","typeGuard":null,"tryCatchPattern":"var e *apierror.APIError\nif errors.As(err, &e) && e.HTTPCode() == 409 {\n    // name already exists: use it or pick a new unique name\n}","preventionTips":["Generate globally unique bucket names (project prefix + random suffix).","Treat 409 AlreadyExists as idempotent success when the existing bucket is yours.","Enable the Cloud Storage API on the project before creating buckets.","Grant storage.buckets.create to the service account."],"tags":["gcs","bucket-creation","iam","name-conflict","cloudstorage"],"backgroundTag":"bucket-name-already-exists","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"}