Fix crash if log file can't be opened (#1937)

This commit is contained in:
Joe Lim authored and GitHub committed 2025-03-21 18:56:13 +11:00
1 parent 9b1f8386fa
commit ad6fa3fa73
2 files changed
+14 -14

No files matched your search

+13 -13
View File
@@ -26,6 +26,19 @@ func init() {
}
func run() {
if gLogPath != "" {
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
log.Fatalf("failed to open log file: %s", err)
}
defer f.Close()
log.SetOutput(f)
} else {
log.SetOutput(io.Discard)
}
log.Print("hi!")
var screen tcell.Screen
var err error
if screen, err = tcell.NewScreen(); err != nil {
@@ -37,19 +50,6 @@ func run() {
screen.EnableMouse()
}
if gLogPath != "" {
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
panic(err)
}
defer f.Close()
log.SetOutput(f)
} else {
log.SetOutput(io.Discard)
}
log.Print("hi!")
ui := newUI(screen)
nav := newNav(ui.wins[0].h)
app := newApp(ui, nav)