matcha
matcha copied to clipboard
BUG: Unchecked tmpFile.Close() error in external editor
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
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.