Fix crash if log file can't be opened (#1937)
This commit is contained in:
1 parent
9b1f8386fa
commit
ad6fa3fa73
2 files changed
+14
-14
No files matched your search
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user