Skip to content

Commit

Permalink
slogutil: fix RecoverAndExit
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Feb 27, 2025
1 parent 5865a4b commit c94fe95
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions logutil/slogutil/defer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ func RecoverAndLogDefault(ctx context.Context) {
PrintRecovered(ctx, l, v)
}

// RecoverAndExit recovers a panic, logs it using l, and then exits with the
// given exit code. l must not be nil.
// RecoverAndExit recovers a panic and, if there is one logs it using l and then
// exits with the given exit code. l must not be nil.
func RecoverAndExit(ctx context.Context, l *slog.Logger, code osutil.ExitCode) {
PrintRecovered(ctx, l, recover())
v := recover()
if v == nil {
return
}

PrintRecovered(ctx, l, v)

os.Exit(code)
}
Expand Down

0 comments on commit c94fe95

Please sign in to comment.