From 6b004f6a5f2c3c21e6c53f64b932ae5fb0c75df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E6=99=BA=E8=B6=850668000959?= Date: Tue, 9 Jun 2026 09:52:48 +0800 Subject: [PATCH] fix: explicitly ignore Close() errors on temp file write/sync failure paths --- pkg/channels/wecom/media.go | 2 +- pkg/tools/fs/filesystem.go | 4 ++-- pkg/tools/normalization.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/channels/wecom/media.go b/pkg/channels/wecom/media.go index 974a3bf4..1494b579 100644 --- a/pkg/channels/wecom/media.go +++ b/pkg/channels/wecom/media.go @@ -334,7 +334,7 @@ func (c *WeComChannel) storeRemoteMedia( } tmpPath := tmpFile.Name() if _, writeErr := tmpFile.Write(data); writeErr != nil { - tmpFile.Close() + _ = tmpFile.Close() _ = os.Remove(tmpPath) return "", fmt.Errorf("write temp file: %w", writeErr) } diff --git a/pkg/tools/fs/filesystem.go b/pkg/tools/fs/filesystem.go index 262d88d9..69717450 100644 --- a/pkg/tools/fs/filesystem.go +++ b/pkg/tools/fs/filesystem.go @@ -1108,7 +1108,7 @@ func (r *sandboxFs) WriteFile(path string, data []byte) error { } if _, err := tmpFile.Write(data); err != nil { - tmpFile.Close() + _ = tmpFile.Close() root.Remove(tmpRelPath) return fmt.Errorf("failed to write temp file: %w", err) } @@ -1116,7 +1116,7 @@ func (r *sandboxFs) WriteFile(path string, data []byte) error { // CRITICAL: Force sync to storage medium before rename. // This ensures data is physically written to disk, not just cached. if err := tmpFile.Sync(); err != nil { - tmpFile.Close() + _ = tmpFile.Close() root.Remove(tmpRelPath) return fmt.Errorf("failed to sync temp file: %w", err) } diff --git a/pkg/tools/normalization.go b/pkg/tools/normalization.go index 3a76c5d9..7ced32bb 100644 --- a/pkg/tools/normalization.go +++ b/pkg/tools/normalization.go @@ -230,7 +230,7 @@ func storeInlineDataURL( } tmpPath := tmpFile.Name() if _, err = tmpFile.Write(decoded); err != nil { - tmpFile.Close() + _ = tmpFile.Close() _ = os.Remove(tmpPath) return "", fmt.Sprintf("[Tool returned inline media content (%s) but it could not be stored.]", mimeType) }