matcha icon indicating copy to clipboard operation
matcha copied to clipboard

BUG: Unchecked tmpFile.Close() error in external editor

Open andrinoff opened this issue 7 months ago • 1 comments

Describe the bug In main.go line 2252, tmpFile.Close() is called but error is ignored. If Close() fails, writes may be lost but editor proceeds anyway.

To reproduce Examine main.go lines 2245-2252:

if _, err := tmpFile.WriteString(body); err != nil {
    tmpFile.Close()
    os.Remove(tmpPath)
    return func() tea.Msg {
        return tui.EditorFinishedMsg{Err: fmt.Errorf("writing temp file: %w", err)}
    }
}
tmpFile.Close()  // Error ignored

Expected behavior Check Close() error before opening editor.

Additional context

  • Good first issue
  • Similar to #716
  • Line 2246 Close() in error path also unchecked

Suggested fix:

if _, err := tmpFile.WriteString(body); err != nil {
    tmpFile.Close()
    os.Remove(tmpPath)
    return func() tea.Msg {
        return tui.EditorFinishedMsg{Err: fmt.Errorf("writing temp file: %w", err)}
    }
}
if err := tmpFile.Close(); err != nil {
    os.Remove(tmpPath)
    return func() tea.Msg {
        return tui.EditorFinishedMsg{Err: fmt.Errorf("closing temp file: %w", err)}
    }
}

OS All platforms

andrinoff avatar Apr 21 '26 09:04 andrinoff

This has had no activity for 30 days. It will be closed in 14 days unless updated. Comment or remove the stale label to keep it open.

floatpanebot avatar May 22 '26 06:05 floatpanebot