diff --git a/cmd/root.go b/cmd/root.go index c37c1d7d..a36c6ee2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -190,10 +190,14 @@ func Execute() { sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) - // Create a goroutine to watch for cancellation signals + // Create a goroutine to watch for cancellation signals and aborting the + // running command. Note that bubbletea converts ^C to a Quit message, + // so we also need to handle that, but we still need to deal with the + // regular signals. go func() { select { case <-sigs: + log.Info("Received signal, shutting down") cancel() case <-ctx.Done(): } diff --git a/cmd/tea_ensuretoken.go b/cmd/tea_ensuretoken.go index 388acb22..146a5eb9 100644 --- a/cmd/tea_ensuretoken.go +++ b/cmd/tea_ensuretoken.go @@ -469,6 +469,10 @@ func getOauthToken(ctx context.Context, oi OvermindInstance, requiredScopes []st os.Exit(1) } + if m.token == nil { + fmt.Println("Error running program: no token received") + os.Exit(1) + } tok, err := josejwt.ParseSigned(m.token.AccessToken, []jose.SignatureAlgorithm{jose.RS256}) if err != nil { fmt.Println("Error running program: received invalid token:", err) diff --git a/cmd/tea_taskmodel.go b/cmd/tea_taskmodel.go index 7a6ed685..50efb23a 100644 --- a/cmd/tea_taskmodel.go +++ b/cmd/tea_taskmodel.go @@ -1,32 +1,13 @@ package cmd import ( - "context" "fmt" - "os" - "os/signal" - "syscall" "github.com/charmbracelet/bubbles/spinner" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" ) -// waitForCancellation returns a tea.Cmd that will wait for SIGINT and SIGTERM and run the provided cancel on receipt. -func waitForCancellation(ctx context.Context, cancel context.CancelFunc) tea.Cmd { - sigs := make(chan os.Signal, 1) - signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) - - return func() tea.Msg { - select { - case <-sigs: - cancel() - case <-ctx.Done(): - } - return tea.Quit - } -} - type taskStatus int const ( diff --git a/cmd/tea_terraform.go b/cmd/tea_terraform.go index 3e0a5750..ec969b84 100644 --- a/cmd/tea_terraform.go +++ b/cmd/tea_terraform.go @@ -79,7 +79,6 @@ func (m *cmdModel) Init() tea.Cmd { // don't init sources on test-fake runs // m.tasks["02_config"] = NewInitialiseSourcesModel() return tea.Batch( - waitForCancellation(m.ctx, m.cancel), m.tasks["00_oi"].Init(), m.tasks["01_token"].Init(), // m.tasks["02_config"].Init(), @@ -95,7 +94,6 @@ func (m *cmdModel) Init() tea.Cmd { m.tasks["02_config"] = NewInitialiseSourcesModel(m.width) return tea.Batch( - waitForCancellation(m.ctx, m.cancel), m.tasks["00_oi"].Init(), m.tasks["01_token"].Init(), m.tasks["02_config"].Init(), diff --git a/tracing/main.go b/tracing/main.go index cbfb0e39..15df4806 100644 --- a/tracing/main.go +++ b/tracing/main.go @@ -101,7 +101,7 @@ func InitTracer(opts ...otlptracehttp.Option) error { // setup recovery for an unexpected panic in this function defer sentry.Flush(2 * time.Second) defer sentry.Recover() - log.Info("sentry configured") + log.Debug("sentry configured") } client := otlptracehttp.NewClient(opts...)