{"record":{"id":"96af100f02ffa752","repo":"flipped-aurora/gin-vue-admin","slug":"delete-failed-code-d","errorCode":null,"errorMessage":"delete failed, code: %d","messagePattern":"delete failed, code: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/upload/qiniu.go","lineNumber":125,"sourceCode":"\tret, err := bucketManager.Batch(operations)\n\tif err != nil {\n\t\t// 部分 key 失败时 Batch 仍可能返回结果，这里仅当完全没有结果时视为致命错误。\n\t\tif len(ret) == 0 {\n\t\t\tlogger.WithCtx(ctx).Mod(\"upload\").Err(err).Error(\"function bucketManager.Batch() failed\")\n\t\t\treturn nil, errors.New(\"function bucketManager.Batch() failed, err:\" + err.Error())\n\t\t}\n\t\tlogger.WithCtx(ctx).Mod(\"upload\").Err(err).Error(\"function bucketManager.Batch() partial failure\")\n\t}\n\n\tfailed := make([]DeleteFailure, 0)\n\tfor i, op := range ret {\n\t\t// 200 / 204 视为删除成功\n\t\tif op.Code != http.StatusOK && op.Code != http.StatusNoContent {\n\t\t\tvar key string\n\t\t\tif i < len(keys) {\n\t\t\t\tkey = keys[i]\n\t\t\t}\n\t\t\tfailed = append(failed, DeleteFailure{Key: key, Err: fmt.Errorf(\"delete failed, code: %d\", op.Code)})\n\t\t}\n\t}\n\treturn failed, nil\n}\n\n// ListFiles 按前缀列举对象，cursor 映射为七牛的 marker。\nfunc (*Qiniu) ListFiles(ctx context.Context, prefix, cursor string, limit int) ([]FileInfo, string, bool, error) {\n\tif limit <= 0 {\n\t\tlimit = 100\n\t}\n\n\tbucketManager := newBucketManager()\n\tentries, _, nextMarker, hasNext, err := bucketManager.ListFiles(global.GVA_CONFIG.Qiniu.Bucket, prefix, \"\", cursor, limit)\n\tif err != nil {\n\t\tlogger.WithCtx(ctx).Mod(\"upload\").Err(err).Error(\"function bucketManager.ListFiles() failed\")\n\t\treturn nil, \"\", false, errors.New(\"function bucketManager.ListFiles() failed, err:\" + err.Error())\n\t}\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/utils/upload/qiniu.go#L107-L143","documentation":"The Qiniu DeleteFiles implementation batch-deletes keys and treats HTTP 200/204 as success. Any operation returning another status code produces a DeleteFailure with \"delete failed, code: %d\". Note the key may be empty when the response index exceeds the keys slice, so correlate by position carefully.","triggerScenarios":"Calling DeleteFiles on the qiniu uploader when an op.Code is neither 200 nor 204 — e.g. 631 (bucket not found), 612 (no such file), or 401/403 auth failures from Qiniu's batch API.","commonSituations":"Expired or wrong AccessKey/Secret; deleting keys already removed (612); bucket name mismatch between config and request; Qiniu status codes outside the standard 200/204 set used here.","solutions":["Check the returned op.Code against Qiniu's status code table (612 = file not found is usually harmless).","Verify qiniu AccessKey/SecretKey and bucket configuration are valid and not expired.","Treat 612 (no such file) as success in caller logic if idempotent deletes are desired.","Retry the failed keys individually; other keys in the batch may have succeeded."],"exampleFix":"// before\nfailed, _ := uploader.DeleteFiles(ctx, keys)\n\n// after\nfailed, err := uploader.DeleteFiles(ctx, keys)\nfor _, f := range failed {\n    if !strings.Contains(f.Err.Error(), \"code: 612\") { // ignore already-deleted\n        log.Printf(\"delete %s failed: %v\", f.Key, f.Err)\n    }\n}","handlingStrategy":"try-catch","validationCode":"if len(keys) == 0 {\n    return nil // nothing to delete\n}\nfor _, k := range keys {\n    if strings.TrimSpace(k) == \"\" {\n        return errors.New(\"empty key in qiniu batch delete\")\n    }\n}","typeGuard":null,"tryCatchPattern":"failed, err := uploader.DeleteFiles(ctx, keys)\nif err != nil {\n    return err\n}\nfor _, f := range failed {\n    if strings.Contains(f.Err.Error(), \"code: 612\") {\n        continue // file already gone; treat as success\n    }\n    log.Printf(\"qiniu delete failed: key=%s err=%v\", f.Key, f.Err)\n}","preventionTips":["Keep Qiniu AK/SK valid and rotate before expiry","Map Qiniu status codes (612 no-such-file, 631 bad bucket) to actionable messages","Make deletes idempotent by ignoring already-deleted codes","Confirm bucket name matches the configured uploader"],"tags":["qiniu","object-storage","delete","cloud"],"backgroundTag":"object-delete-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}