{"record":{"id":"78a1202d3c39b4dc","repo":"cloudreve/cloudreve","slug":"failed-to-delete-files-v","errorCode":null,"errorMessage":"failed to delete files: %v","messagePattern":"failed to delete files: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/filemanager/driver/cos/cos.go","lineNumber":345,"sourceCode":"\t\t\t\tObjects: lo.Map(group, func(item string, index int) cossdk.Object {\n\t\t\t\t\treturn cossdk.Object{Key: item}\n\t\t\t\t}),\n\t\t\t\tQuiet: true,\n\t\t\t})\n\t\tif err != nil {\n\t\t\tlastError = err\n\t\t\tfailed = append(failed, group...)\n\t\t\tcontinue\n\t\t}\n\n\t\tfor _, v := range res.Errors {\n\t\t\thandler.l.Debug(\"Failed to delete file: %s, Code:%s, Message:%s\", v.Key, v.Code, v.Key)\n\t\t\tfailed = append(failed, v.Key)\n\t\t}\n\t}\n\n\tif len(failed) > 0 && lastError == nil {\n\t\tlastError = fmt.Errorf(\"failed to delete files: %v\", failed)\n\t}\n\n\treturn failed, lastError\n}\n\n// Thumb 获取文件缩略图\nfunc (handler Driver) Thumb(ctx context.Context, expire *time.Time, ext string, e fs.Entity) (string, error) {\n\tw, h := handler.settings.ThumbSize(ctx)\n\tthumbParam := fmt.Sprintf(\"imageMogr2/thumbnail/%dx%d\", w, h)\n\n\tenco := handler.settings.ThumbEncode(ctx)\n\tswitch enco.Format {\n\tcase \"jpg\", \"webp\":\n\t\tthumbParam += fmt.Sprintf(\"/format/%s/rquality/%d\", enco.Format, enco.Quality)\n\tcase \"png\":\n\t\tthumbParam += fmt.Sprintf(\"/format/%s\", enco.Format)\n\t}\n","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/cloudreve/cloudreve/blob/20c95ad73f3a8bcb72887fea91ff31ab24fa1011/pkg/filemanager/driver/cos/cos.go#L327-L363","documentation":"After issuing batched COS delete requests, some keys came back in the response's Errors array, so the driver returns the list of keys it could not delete (the debug log prints each key's Code). This is a partial failure: the rest of the batch was deleted; the returned error aggregates the failed key names.","triggerScenarios":"Deleting objects the credentials lack cos:DeleteObject permission for; keys already gone (NoSuchKey) or being deleted concurrently; intermittent server errors on some items in a large batch.","commonSituations":"Bulk-cleaning directories where some files were already removed; sub-account CAM policies granting list but not delete; two workers racing to empty the same directory.","solutions":["Re-run the delete for just the failed key list; transient per-key errors succeed on retry","Enable debug logging and read the 'Failed to delete file' lines to get each key's Code (AccessDenied vs NoSuchKey) before changing anything","For AccessDenied, grant cos:DeleteObject on the bucket/prefix in the CAM policy","Treat NoSuchKey as acceptable if your flow only needs eventual absence"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"failed, err := driver.Delete(ctx, keys)\nif len(failed) > 0 {\n    // partial failure: retry only the failed subset once\n    failed2, err2 := driver.Delete(ctx, failed)\n    if len(failed2) > 0 {\n        log.Warn(\"keys still failing after retry: %v\", failed2)\n    }\n    _ = err2\n}\nif err != nil && !strings.Contains(err.Error(), \"failed to delete files\") {\n    return err // transport-level failure, different handling\n}","preventionTips":["Treat Delete as partial-by-design: always process the returned failed-keys list","Filter keys known to be absent before batching to avoid NoSuchKey noise","Grant cos:DeleteObject in CAM policies used for cleanup jobs"],"tags":["cos","tencent-cloud","batch-delete","partial-failure","storage","permissions"],"backgroundTag":null,"analyzedSha":"20c95ad73f3a8bcb72887fea91ff31ab24fa1011","analyzedAt":"2026-08-16T01:42:55.403Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}