cloudreve/cloudreve · warning
failed to delete files: %v
Error message
failed to delete files: %v
What it means
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.
Source
Thrown at pkg/filemanager/driver/cos/cos.go:345
Objects: lo.Map(group, func(item string, index int) cossdk.Object {
return cossdk.Object{Key: item}
}),
Quiet: true,
})
if err != nil {
lastError = err
failed = append(failed, group...)
continue
}
for _, v := range res.Errors {
handler.l.Debug("Failed to delete file: %s, Code:%s, Message:%s", v.Key, v.Code, v.Key)
failed = append(failed, v.Key)
}
}
if len(failed) > 0 && lastError == nil {
lastError = fmt.Errorf("failed to delete files: %v", failed)
}
return failed, lastError
}
// Thumb 获取文件缩略图
func (handler Driver) Thumb(ctx context.Context, expire *time.Time, ext string, e fs.Entity) (string, error) {
w, h := handler.settings.ThumbSize(ctx)
thumbParam := fmt.Sprintf("imageMogr2/thumbnail/%dx%d", w, h)
enco := handler.settings.ThumbEncode(ctx)
switch enco.Format {
case "jpg", "webp":
thumbParam += fmt.Sprintf("/format/%s/rquality/%d", enco.Format, enco.Quality)
case "png":
thumbParam += fmt.Sprintf("/format/%s", enco.Format)
}
View on GitHub (pinned to 20c95ad73f)
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
Defensive patterns
Strategy: fallback
Try / catch
failed, err := driver.Delete(ctx, keys)
if len(failed) > 0 {
// partial failure: retry only the failed subset once
failed2, err2 := driver.Delete(ctx, failed)
if len(failed2) > 0 {
log.Warn("keys still failing after retry: %v", failed2)
}
_ = err2
}
if err != nil && !strings.Contains(err.Error(), "failed to delete files") {
return err // transport-level failure, different handling
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to initialize multipart upload: %w
- failed to upload chunk #%d: %w
- failed to get uploaded file size: %w
- file with the same name existed or unavailable
- failed to parse COS bucket server url: %w
AI-assisted analysis of cloudreve/cloudreve@20c95ad73f (2026-08-16).
Data as JSON: /api/errors/78a1202d3c39b4dc.
Report an issue: GitHub.