From 50dabd5fe32356d9b12bd3fe92ae0259fe71acfb Mon Sep 17 00:00:00 2001 From: alex <53851759+alxxjohn@users.noreply.github.com> Date: Tue, 16 Jun 2026 16:49:45 -0400 Subject: [PATCH] Fix for Writable file handle closed without error handling Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- internal/codeguard/runner/support/diff_command.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/codeguard/runner/support/diff_command.go b/internal/codeguard/runner/support/diff_command.go index 375a059..43902c5 100644 --- a/internal/codeguard/runner/support/diff_command.go +++ b/internal/codeguard/runner/support/diff_command.go @@ -121,7 +121,7 @@ func copyDir(srcDir string, dstDir string) error { }) } -func copyFile(srcPath string, dstPath string, mode os.FileMode) error { +func copyFile(srcPath string, dstPath string, mode os.FileMode) (err error) { src, err := os.Open(srcPath) if err != nil { return err @@ -136,7 +136,11 @@ func copyFile(srcPath string, dstPath string, mode os.FileMode) error { if err != nil { return err } - defer dst.Close() + defer func() { + if closeErr := dst.Close(); err == nil && closeErr != nil { + err = closeErr + } + }() _, err = io.Copy(dst, src) return err