Skip to content

Commit

Permalink
fix: print error to stdout prior to exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
sreya committed Aug 15, 2024
1 parent c07d2c2 commit 614284e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/envbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"os"
"os/signal"
"runtime"
Expand All @@ -17,8 +18,8 @@ func main() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT, syscall.SIGWINCH)
go func() {
log := slog.Make(slogjson.Sink(os.Stderr))
ctx := context.Background()
log := slog.Make(slogjson.Sink(os.Stderr))
log.Info(ctx, "waiting for signal")
<-sigs
log.Info(ctx, "got signal")
Expand All @@ -38,6 +39,7 @@ func main() {
}()
_, err := cli.Root(ch).ExecuteC()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
runtime.Goexit()
Expand Down

0 comments on commit 614284e

Please sign in to comment.