{"record":{"id":"e49bb3d7ccaefe1c","repo":"flipped-aurora/gin-vue-admin","slug":"function-config-loaddefaultconfig-failed-err-e49bb3","errorCode":null,"errorMessage":"function config.LoadDefaultConfig() failed, err:","messagePattern":"function config\\.LoadDefaultConfig\\(\\) failed, err:","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/upload/cloudflare_r2.go","lineNumber":212,"sourceCode":"\t\thasMore = *out.IsTruncated\n\t}\n\treturn files, nextCursor, hasMore, nil\n}\n\nfunc (*CloudflareR2) newR2Client() (*s3.Client, error) {\n\tendpoint := fmt.Sprintf(\"https://%s.r2.cloudflarestorage.com\", global.GVA_CONFIG.CloudflareR2.AccountID)\n\n\tcfg, err := config.LoadDefaultConfig(context.TODO(),\n\t\tconfig.WithRegion(\"auto\"),\n\t\tconfig.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(\n\t\t\tglobal.GVA_CONFIG.CloudflareR2.AccessKeyID,\n\t\t\tglobal.GVA_CONFIG.CloudflareR2.SecretAccessKey,\n\t\t\t\"\",\n\t\t)),\n\t)\n\tif err != nil {\n\t\tlogger.Bg().Mod(\"upload\").Err(err).Error(\"function config.LoadDefaultConfig() failed\")\n\t\treturn nil, errors.New(\"function config.LoadDefaultConfig() failed, err:\" + err.Error())\n\t}\n\n\treturn s3.NewFromConfig(cfg, func(o *s3.Options) {\n\t\to.BaseEndpoint = aws.String(endpoint)\n\t}), nil\n}\n","sourceCodeStart":194,"sourceCodeEnd":219,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/utils/upload/cloudflare_r2.go#L194-L219","documentation":"newR2Client constructs an aws.Config via config.LoadDefaultConfig using the statically provided Cloudflare R2 credentials; an SDK error there is wrapped in this message. Called lazily by every public R2 operation, so any upload/delete/list/exists call can surface it. The failure is in building the AWS config, not in talking to R2.","triggerScenarios":"Any public method on CloudflareR2 when LoadDefaultConfig fails — typically because shared-config/profile resolution (AWS_PROFILE, AWS_CONFIG_FILE) or region resolution errors, overriding the static credentials.","commonSituations":"Container images with AWS_PROFILE set to a nonexistent profile, corrupt shared credentials file mounted into the pod, SDK env var interference, or an SDK version change altering default config-file loading behavior.","solutions":["Read the wrapped err text to see which config source failed","Unset/fix AWS_PROFILE, AWS_CONFIG_FILE, AWS_SHARED_CREDENTIALS_FILE in the server environment","Confirm CloudflareR2.AccessKeyID and SecretAccessKey are present in config","Upgrade/align the aws-sdk-go-v2 config module versions in go.mod to avoid known LoadDefaultConfig regressions","Reproduce with a minimal LoadDefaultConfig call in a test using testutil config loading"],"exampleFix":"// before (deployment yaml)\nenv:\n  - name: AWS_PROFILE\n    value: default\n// after\nenv: []  # let static credentials from GVA_CONFIG be used","handlingStrategy":"validation","validationCode":"if cfg.CloudflareR2.AccessKeyID == \"\" || cfg.CloudflareR2.SecretAccessKey == \"\" {\n    return errors.New(\"CloudflareR2 credentials missing\")\n}\nif os.Getenv(\"AWS_PROFILE\") != \"\" {\n    return errors.New(\"AWS_PROFILE would override static R2 credentials\")\n}","typeGuard":"null","tryCatchPattern":"client, err := newR2Client(endpoint)\nif err != nil {\n    logger.Error(\"R2 client init failed\", zap.Error(err))\n    return fmt.Errorf(\"r2 client init: %w\", err)\n}","preventionTips":["Sanitize the deployment environment of stray AWS_* env vars","Fail fast at startup by eagerly constructing the R2 client","Keep aws-sdk-go-v2 versions consistent and updated in go.mod","Store R2 keys in config/secrets manager, never the shared-credentials file"],"tags":["cloudflare-r2","aws","config","credentials"],"backgroundTag":"aws-config-load-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}