From f7be21bb119cee95a8d49edadfab396433ff3051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E6=99=BA=E8=B6=850668000959?= Date: Sun, 7 Jun 2026 11:53:24 +0800 Subject: [PATCH] fix: check Close() error after downloading media file --- pkg/utils/media.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/utils/media.go b/pkg/utils/media.go index 823ca155e..a9c2497d8 100644 --- a/pkg/utils/media.go +++ b/pkg/utils/media.go @@ -146,7 +146,6 @@ func DownloadFile(urlStr, filename string, opts DownloadOptions) string { }) return "" } - defer out.Close() if _, err := io.Copy(out, resp.Body); err != nil { out.Close() @@ -156,6 +155,13 @@ func DownloadFile(urlStr, filename string, opts DownloadOptions) string { }) return "" } + if err := out.Close(); err != nil { + logger.ErrorCF(opts.LoggerPrefix, "Failed to close downloaded file", map[string]any{ + "error": err.Error(), + }) + os.Remove(localPath) + return "" + } logger.DebugCF(opts.LoggerPrefix, "File downloaded successfully", map[string]any{ "path": localPath,