Merge pull request #3033 from chengzhichao-xydt/codex/media-close-errors

fix: check Close() error after downloading media file
This commit is contained in:
Mauro 2026-06-07 14:00:34 +02:00 committed by GitHub
commit 7c18fe8421
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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,