{"record":{"id":"7a6bf21ee4699cf2","repo":"juicedata/juicefs","slug":"failed-to-load-config-s-7a6bf2","errorCode":null,"errorMessage":"failed to load config: %s","messagePattern":"failed to load config: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/object/space.go","lineNumber":69,"sourceCode":"\t}\n\treturn notSupported\n}\n\nfunc newSpace(endpoint, accessKey, secretKey, token string) (ObjectStorage, error) {\n\tif !strings.Contains(endpoint, \"://\") {\n\t\tendpoint = fmt.Sprintf(\"https://%s\", endpoint)\n\t}\n\turi, _ := url.ParseRequestURI(endpoint)\n\tssl := strings.ToLower(uri.Scheme) == \"https\"\n\thostParts := strings.Split(uri.Host, \".\")\n\tbucket := hostParts[0]\n\tregion := hostParts[1]\n\tendpoint = uri.Scheme + \"://\" + uri.Host[len(bucket)+1:]\n\n\tawsCfg, err := config.LoadDefaultConfig(ctx, append(defaultChecksumOpts(),\n\t\tconfig.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKey, secretKey, token)))...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load config: %s\", err)\n\t}\n\tclient := s3.NewFromConfig(awsCfg, func(options *s3.Options) {\n\t\toptions.Region = region\n\t\toptions.BaseEndpoint = aws.String(endpoint)\n\t\toptions.EndpointOptions.DisableHTTPS = !ssl\n\t\toptions.UsePathStyle = false\n\t\toptions.HTTPClient = httpClient\n\t\toptions.APIOptions = append(options.APIOptions, func(stack *smithymiddleware.Stack) error {\n\t\t\treturn v4.SwapComputePayloadSHA256ForUnsignedPayloadMiddleware(stack)\n\t\t}, addS3UserAgent)\n\t\toptions.RetryMaxAttempts = 1\n\t})\n\treturn &space{s3client{bucket: bucket, s3: client, region: region}}, nil\n}\n\nfunc init() {\n\tRegister(\"space\", newSpace)\n}","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/object/space.go#L51-L87","documentation":"newSpace (the PIKA/space object storage driver built on the AWS SDK v2) fails while loading the AWS configuration (region, credentials, retry options). config.LoadDefaultConfig aggregates config from env vars, shared config/credentials files, and explicit options; any fatal problem there aborts client construction before an S3 request is ever made.","triggerScenarios":"config.LoadDefaultConfig returns an error — typically malformed shared config files (~/.aws/config, ~/.aws/credentials), invalid AWS_* env values (e.g. bad retry mode), or invalid options passed programmatically.","commonSituations":"Corrupted or hand-edited AWS shared credentials file; invalid AWS_RETRY_MODE or AWS_MAX_ATTEMPTS env values; unparseable profile definitions when running on a host with AWS tooling installed.","solutions":["Validate ~/.aws/config and ~/.aws/credentials syntax (aws configure list will surface parse errors).","Check AWS_* environment variables for invalid values (AWS_RETRY_MODE, AWS_MAX_ATTEMPTS, AWS_REGION format).","Since credentials are passed statically via WithCredentialsProvider, unset conflicting AWS_* env vars or pass config.WithSharedConfigProfile/WithRegion explicitly to avoid file loading interference."],"exampleFix":"// before\nawsCfg, err := config.LoadDefaultConfig(ctx, opts...)\n// after (pin config explicitly, avoid env/file surprises)\nawsCfg, err := config.LoadDefaultConfig(ctx, append(opts,\n    config.WithRegion(region),\n    config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(ak, sk, token)))...)","handlingStrategy":"validation","validationCode":"if _, err := ini.LoadFile(filepath.Join(home, \".aws\", \"config\")); err != nil {\n    return fmt.Errorf(\"invalid AWS shared config: %v\", err)\n}\nfor _, k := range []string{\"AWS_RETRY_MODE\", \"AWS_MAX_ATTEMPTS\"} {\n    if v := os.Getenv(k); v != \"\" && !isInt(v) {\n        return fmt.Errorf(\"invalid %s=%s\", k, v)\n    }\n}","typeGuard":null,"tryCatchPattern":"client, err := newSpace(ctx, ...)\nif err != nil && strings.HasPrefix(err.Error(), \"failed to load config\") {\n    // inspect ~/.aws files and AWS_* env vars for malformed values\n    return err\n}","preventionTips":["Pass region and credentials explicitly via config options instead of relying on env/shared files.","Lint AWS config files after manual edits.","Avoid exporting experimental AWS_* env vars on servers running JuiceFS."],"tags":["aws-sdk","config","credentials"],"backgroundTag":"missing-required-config","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"}