{"record":{"id":"8fff844701d65ada","repo":"argoproj/argo-workflows","slug":"failed-to-automatically-create-bucket-s-when-it-s","errorCode":null,"errorMessage":"failed to automatically create bucket %s when it's not present: %w","messagePattern":"failed to automatically create bucket (.+?) when it's not present: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/artifacts/oss/oss.go","lineNumber":246,"sourceCode":"\t\t\tisDir, err := file.IsDirectory(path)\n\t\t\tif err != nil {\n\t\t\t\tlogger.WithError(err).Warn(ctx, \"Failed to test if path is a directory\")\n\t\t\t\treturn false, nil\n\t\t\t}\n\t\t\tbucketName := outputArtifact.OSS.Bucket\n\t\t\terr = setBucketLogging(osscli, bucketName)\n\t\t\tif err != nil {\n\t\t\t\treturn !isTransientOSSErr(ctx, err), err\n\t\t\t}\n\t\t\tif outputArtifact.OSS.CreateBucketIfNotPresent {\n\t\t\t\texists, existsErr := osscli.IsBucketExist(bucketName)\n\t\t\t\tif existsErr != nil {\n\t\t\t\t\treturn !isTransientOSSErr(ctx, existsErr), fmt.Errorf(\"failed to check if bucket %s exists: %w\", bucketName, existsErr)\n\t\t\t\t}\n\t\t\t\tif !exists {\n\t\t\t\t\terr = osscli.CreateBucket(bucketName)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn !isTransientOSSErr(ctx, err), fmt.Errorf(\"failed to automatically create bucket %s when it's not present: %w\", bucketName, err)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbucket, err := osscli.Bucket(bucketName)\n\t\t\tif err != nil {\n\t\t\t\treturn !isTransientOSSErr(ctx, err), err\n\t\t\t}\n\t\t\tobjectName := outputArtifact.OSS.Key\n\t\t\tif outputArtifact.OSS.LifecycleRule != nil {\n\t\t\t\terr = setBucketLifecycleRule(osscli, outputArtifact.OSS)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn !isTransientOSSErr(ctx, err), err\n\t\t\t\t}\n\t\t\t}\n\t\t\tif isDir {\n\t\t\t\tif err = putDirectory(ctx, bucket, objectName, path); err != nil {\n\t\t\t\t\tlogger.WithError(err).Warn(ctx, \"failed to put directory\")\n\t\t\t\t\treturn !isTransientOSSErr(ctx, err), err","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/artifacts/oss/oss.go#L228-L264","documentation":"Raised in Save when createBucketIfNotPresent is true, the bucket does not exist, and osscli.CreateBucket fails to create it. Commonly a permissions problem (RAM user lacks oss:PutBucket), a bucket-name conflict (name globally taken in the region or owned by another account), or invalid bucket configuration (region, name characters, storage class).","triggerScenarios":"Save of an output artifact with createBucketIfNotPresent: true; IsBucketExist returned false; CreateBucket returns an error such as AccessDenied, BucketAlreadyExists, TooManyBuckets, or InvalidBucketName.","commonSituations":"Bucket name already registered by another Aliyun account (OSS names are globally unique per region); RAM policy not updated to allow PutBucket; exceeding the account's bucket quota; region mismatch between endpoint and desired bucket location.","solutions":["Inspect the wrapped OSS error code: BucketAlreadyExists means pick a new globally-unique bucket name; AccessDenied means grant oss:PutBucket to the RAM user/role.","Pre-create the bucket with ossutil mb or the console and set createBucketIfNotPresent: false.","Verify the endpoint/region matches the intended bucket location (creationRegion).","Check account bucket quota (default 100 per region) if the error is TooManyBuckets.","Validate the bucket name (3-63 chars, lowercase letters/numbers/hyphens)."],"exampleFix":"// before (workflow spec)\noss:\n  bucket: my-bucket\n  createBucketIfNotPresent: true\n// after (pre-create outside the workflow)\n# ossutil mb oss://my-argo-artifacts-bucket-2026 --region oss-cn-hangzhou\noss:\n  bucket: my-argo-artifacts-bucket-2026\n  createBucketIfNotPresent: false","handlingStrategy":"validation","validationCode":"// pre-create and verify before workflows run\ncli, _ := oss.New(endpoint, ak, sk)\nif ok, _ := cli.IsBucketExist(bucketName); !ok {\n\tif err := cli.CreateBucket(bucketName); err != nil {\n\t\tpanic(fmt.Sprintf(\"create %s now, not during workflow: %v\", bucketName, err))\n\t}\n}","typeGuard":"func isBucketNameTaken(err error) bool {\n\tse, ok := err.(oss.ServiceError)\n\treturn ok && (se.Code == \"BucketAlreadyExists\" || se.Code == \"BucketAlreadyOwnedByYou\")\n}","tryCatchPattern":"if err := driver.Save(ctx, path, artifact); err != nil {\n\tif strings.Contains(err.Error(), \"failed to automatically create bucket\") {\n\t\tvar se oss.ServiceError\n\t\tif errors.As(err, &se) && (se.Code == \"BucketAlreadyExists\" || se.Code == \"AccessDenied\") {\n\t\t\t// pick unique name or grant oss:PutBucket — retries won't help\n\t\t}\n\t}\n}","preventionTips":["Use globally-unique, environment-prefixed bucket names (org-team-purpose-region).","Disable createBucketIfNotPresent in shared/production accounts and create buckets via Terraform/IaC.","Keep account bucket count under quota; monitor if many ephemeral buckets are created.","Match endpoint region to intended bucket location."],"tags":["oss","bucket","createbucket","permissions"],"backgroundTag":"oss-access-denied","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}