Skip to content

Commit e8b1a06

Browse files
authored
Merge pull request #45 from dispatchrun/fix-43
tui: fix how auth errors are displayed in TUI mode
2 parents f7750a9 + f6a00aa commit e8b1a06

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

cli/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "fmt"
55
type authError struct{}
66

77
func (authError) Error() string {
8-
const message = "Authentication error when contacting the Dispatch API"
8+
const message = "Authentication error"
99
var detail string
1010
switch DispatchApiKeyLocation {
1111
case "env":

cli/run.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,14 @@ Run 'dispatch help run' to learn about Dispatch sessions.`, BridgeSession)
232232
if ctx.Err() != nil {
233233
return
234234
}
235-
switch e := err.(type) {
236-
case authError:
237-
failure(e.Error())
238-
return
239-
default:
240-
slog.Warn(err.Error())
235+
slog.Warn(err.Error())
236+
237+
if tui != nil {
238+
if _, ok := err.(authError); ok {
239+
tui.SetError(err)
240+
}
241241
}
242+
242243
time.Sleep(1 * time.Second)
243244
continue
244245
} else if res == nil {

cli/tui.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ type TUI struct {
8989
windowHeight int
9090
selected *DispatchID
9191

92+
err error
93+
9294
mu sync.Mutex
9395
}
9496

@@ -249,7 +251,7 @@ func (t *TUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
249251
case "s":
250252
// Don't accept s/select until at least one function
251253
// call has been received.
252-
if len(t.calls) > 0 {
254+
if len(t.calls) > 0 && t.err == nil {
253255
cmds = append(cmds, focusSelect)
254256
}
255257
case "t":
@@ -341,6 +343,10 @@ func (t *TUI) View() string {
341343
}
342344
}
343345

346+
if t.err != nil {
347+
statusBarContent = errorStyle.Render(t.err.Error())
348+
}
349+
344350
t.viewport.SetContent(viewportContent)
345351

346352
// Shrink the viewport so it contains the content and status bar only.
@@ -945,6 +951,13 @@ func (t *TUI) Read(b []byte) (int, error) {
945951
return t.logs.Read(b)
946952
}
947953

954+
func (t *TUI) SetError(err error) {
955+
t.mu.Lock()
956+
defer t.mu.Unlock()
957+
958+
t.err = err
959+
}
960+
948961
func statusString(status sdkv1.Status) string {
949962
switch status {
950963
case sdkv1.Status_STATUS_OK:

0 commit comments

Comments
 (0)