From 2e8b56c7194dc81cadcd82d75e8bac3e5a402d35 Mon Sep 17 00:00:00 2001 From: Slug-Boi Date: Tue, 17 Jun 2025 21:28:38 +0200 Subject: [PATCH] refactor: defer remove --- src/cmd/utils/editor.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cmd/utils/editor.go b/src/cmd/utils/editor.go index 676a3ce..42dc882 100644 --- a/src/cmd/utils/editor.go +++ b/src/cmd/utils/editor.go @@ -31,7 +31,7 @@ func HandleEditor() (string, error) { return output, nil } -func LaunchEditor(editor string, filepath string) (string, error) { +func LaunchEditor(editor string, filepath string, ) (string, error) { // Create a temp file or use an existing file var tempFile *os.File var err error @@ -53,6 +53,7 @@ func LaunchEditor(editor string, filepath string) (string, error) { if filepath == "" { tempFile, err = os.CreateTemp("", "cocommit_editor_*.txt") + defer os.Remove(tempFile.Name()) } else { tempFile, err = os.OpenFile(filepath, os.O_RDWR, 0666) } @@ -81,9 +82,6 @@ func LaunchEditor(editor string, filepath string) (string, error) { } // Clean up the temp file - if err := os.Remove(tempFile.Name()); err != nil { - return "", fmt.Errorf("error removing temp file: %v", err) - } if strings.HasSuffix(message, "\n") { message = strings.TrimSuffix(message, "\n") }