{"record":{"id":"c8f36e3095bdda54","repo":"flipped-aurora/gin-vue-admin","slug":"function-bucketmanager-stat-failed-err","errorCode":null,"errorMessage":"function bucketManager.Stat() failed, err:","messagePattern":"function bucketManager\\.Stat\\(\\) failed, err:","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/upload/qiniu.go","lineNumber":89,"sourceCode":"\n// newBucketManager 创建七牛 BucketManager 实例。\nfunc newBucketManager() *storage.BucketManager {\n\tmac := qbox.NewMac(global.GVA_CONFIG.Qiniu.AccessKey, global.GVA_CONFIG.Qiniu.SecretKey)\n\tcfg := qiniuConfig()\n\treturn storage.NewBucketManager(mac, cfg)\n}\n\n// Exists 检查对象是否存在，七牛 code 612（或 \"no such file\"）视为不存在。\nfunc (*Qiniu) Exists(ctx context.Context, key string) (bool, error) {\n\tbucketManager := newBucketManager()\n\tif _, err := bucketManager.Stat(global.GVA_CONFIG.Qiniu.Bucket, key); err != nil {\n\t\tmsg := err.Error()\n\t\t// 七牛 612 表示资源不存在\n\t\tif strings.Contains(msg, \"612\") || strings.Contains(msg, \"no such file\") || strings.Contains(msg, \"no such file or directory\") {\n\t\t\treturn false, nil\n\t\t}\n\t\tlogger.WithCtx(ctx).Mod(\"upload\").Err(err).Error(\"function bucketManager.Stat() failed\")\n\t\treturn false, errors.New(\"function bucketManager.Stat() failed, err:\" + err.Error())\n\t}\n\treturn true, nil\n}\n\n// DeleteFiles 批量删除对象，通过通用 Batch 接口，逐项检查 code（200/204 成功）。\nfunc (*Qiniu) DeleteFiles(ctx context.Context, keys []string) ([]DeleteFailure, error) {\n\tif len(keys) == 0 {\n\t\treturn nil, nil\n\t}\n\n\tbucket := global.GVA_CONFIG.Qiniu.Bucket\n\toperations := make([]string, 0, len(keys))\n\tfor _, key := range keys {\n\t\toperations = append(operations, storage.URIDelete(bucket, key))\n\t}\n\n\tbucketManager := newBucketManager()\n\tret, err := bucketManager.Batch(operations)","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/utils/upload/qiniu.go#L71-L107","documentation":"Wraps the error returned by the Qiniu SDK's bucketManager.Stat() call inside Exists(). Stat() queries the object's metadata; if it fails with anything other than a '612 no such file' response (which Exists treats as a clean false), the error is logged and re-wrapped with this prefix.","triggerScenarios":"Calling Exists(ctx, key) on Qiniu when bucketManager.Stat() returns a non-612 error: invalid credentials, missing bucket, network failure, or malformed key.","commonSituations":"Wrong AK/SK in config, bucket name typo in GVA_CONFIG.Qiniu.Bucket, network egress blocked to Qiniu region endpoint, or SDK returning 401/403/571 errors.","solutions":["Verify GVA_CONFIG.Qiniu access-key/secret-key and bucket name in config.yaml","Check the wrapped err text (suffix after 'err:') for the real Qiniu code (401 auth, 403 permission, network timeout)","Confirm network access to the Qiniu zone endpoint for the configured bucket region","If 612-style errors are expected, confirm the message-matching strings cover your SDK version's wording"],"exampleFix":"// before\nok, err := uploadQiniu.Exists(ctx, \"missing-key\") // returns wrapped Stat error on network/auth failure\n// after\nif err != nil && strings.Contains(err.Error(), \"401\") {\n    // fix credentials in config.yaml before retrying\n}","handlingStrategy":"try-catch","validationCode":"// verify config before calling\nif global.GVA_CONFIG.Qiniu.Bucket == \"\" || global.GVA_CONFIG.Qiniu.AccessKey == \"\" {\n    return fmt.Errorf(\"qiniu config incomplete\")\n}","typeGuard":null,"tryCatchPattern":"ok, err := q.Exists(ctx, key)\nif err != nil {\n    if strings.Contains(err.Error(), \"401\") || strings.Contains(err.Error(), \"403\") {\n        // fix credentials\n    } else {\n        // transient: retry or degrade\n    }\n}","preventionTips":["Validate qiniu config keys at startup","Log the underlying wrapped error for diagnosis","Distinguish 612/not-found from auth and network errors in callers"],"tags":["qiniu","upload","object-storage","network"],"backgroundTag":"object-storage-stat-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}