{"record":{"id":"c3973fa5204b3efa","repo":"juicedata/juicefs","slug":"failed-to-create-bucket-s-s-previous-error-s-c3973f","errorCode":null,"errorMessage":"Failed to create bucket %s: %s, previous error: %s","messagePattern":"Failed to create bucket (.+?): (.+?), previous error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/format.go","lineNumber":344,"sourceCode":"\tb := make([]rune, n)\n\tr := rand.New(rand.NewSource(time.Now().UnixNano()))\n\tfor i := range b {\n\t\tb[i] = letters[r.Intn(len(letters))]\n\t}\n\treturn string(b)\n}\n\nfunc doTesting(ctx context.Context, store object.ObjectStorage, key string, data []byte) error {\n\tif err := store.Put(ctx, key, bytes.NewReader(data)); err != nil {\n\t\tif strings.Contains(strings.ToLower(err.Error()), \"denied\") {\n\t\t\treturn fmt.Errorf(\"Failed to put: %s\", err)\n\t\t}\n\t\tif err2 := store.Create(ctx); err2 != nil {\n\t\t\tif strings.Contains(err.Error(), \"NoSuchBucket\") {\n\t\t\t\treturn fmt.Errorf(\"Failed to create bucket %s: %s, previous error: %s\\nPlease create bucket %s manually, then format again.\",\n\t\t\t\t\tstore, err2, err, store)\n\t\t\t} else {\n\t\t\t\treturn fmt.Errorf(\"Failed to create bucket %s: %s, previous error: %s\",\n\t\t\t\t\tstore, err2, err)\n\t\t\t}\n\t\t}\n\t\tif err := store.Put(ctx, key, bytes.NewReader(data)); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to put: %s\", err)\n\t\t}\n\t}\n\t// GLACIER storage class doesn't allow read after write\n\tif _, ok := ctx.Value(object.TierKey{}).(uint8); ok {\n\t\treturn nil\n\t}\n\tp, err := store.Get(ctx, key, 0, -1)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to get: %s\", err)\n\t}\n\tdata2, err := io.ReadAll(p)\n\t_ = p.Close()\n\tif err != nil {","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/cmd/format.go#L326-L362","documentation":"The initial Put failed, the store's Create (bucket creation) attempt also failed, and the original error was NOT NoSuchBucket — so JuiceFS reports the create-bucket failure together with the original Put error without the manual-creation hint. This indicates a general connectivity/auth problem rather than a missing bucket.","triggerScenarios":"Put fails (network error, auth error, DNS failure) and store.Create also fails — e.g. invalid access keys rejected on both calls, unreachable endpoint, or a backend where Create is unsupported and returns its own error.","commonSituations":"Wrong access/secret keys; endpoint typo causing connection failures; self-signed cert issues against an S3-compatible store; firewall blocking the endpoint.","solutions":["Check both errors: the create error usually reveals the root cause (auth vs network)","Validate credentials with the provider CLI against the same endpoint","Test endpoint reachability: `curl -v https://endpoint`","For S3-compatible stores, confirm the provider supports the ListBuckets/CreateBucket semantics JuiceFS uses"],"exampleFix":"// before\n--storage-url s3://bucket (endpoint misspelled)\n// after\n--storage-url s3://bucket --endpoint https://s3.us-east-1.amazonaws.com (correct endpoint)","handlingStrategy":"try-catch","validationCode":"// pre-flight: verify auth and endpoint\n// aws s3 ls s3://mybucket --endpoint-url $ENDPOINT","typeGuard":"func isCreateFailed(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"Failed to create bucket\") && !strings.Contains(err.Error(), \"NoSuchBucket\")\n}","tryCatchPattern":"err := doTesting(ctx, store, key, data)\nif err != nil && strings.Contains(err.Error(), \"previous error\") {\n    // read both errors; usually credentials or endpoint are wrong\n}","preventionTips":["Verify access/secret keys against the exact endpoint before formatting","Test endpoint connectivity with curl or provider CLI","Avoid proxies that intercept TLS to the object store","Confirm the backend supports bucket-creation semantics if relying on auto-create"],"tags":["object-storage","s3","network"],"backgroundTag":"api-request-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}