Skip to content

Commit dcff7f4

Browse files
committed
maintenance: improve config handling
1 parent aa097e9 commit dcff7f4

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

cmd/root.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package cmd
66

77
import (
88
"context"
9+
"fmt"
910
"os"
1011
"os/signal"
1112
"syscall"
@@ -40,6 +41,13 @@ func Execute() {
4041
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
4142
defer cancel()
4243

44+
defer func() {
45+
if r := recover(); r != nil {
46+
fmt.Fprintf(os.Stderr, "%v\n", r)
47+
os.Exit(1)
48+
}
49+
}()
50+
4351
err := rootCmd.ExecuteContext(ctx)
4452
if err != nil {
4553
os.Exit(1)

internal/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ func path() string {
185185
dir = filepath.Join(dir, ".config")
186186
}
187187

188+
if _, err := os.Stat(dir); err != nil {
189+
panic(&ConfigError{Message: err.Error(), Reason: ""})
190+
}
191+
188192
return filepath.Join(dir, "finch.json")
189193
}
190194

0 commit comments

Comments
 (0)