Skip to content

Commit

Permalink
Handle error handling better
Browse files Browse the repository at this point in the history
Don't panic
Add function due to reuse
Catch all errors to appease CI
  • Loading branch information
Seanstoppable committed Oct 7, 2020
1 parent 4e2d2cd commit c0ef9bd
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions modules/cmdrunner/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,28 @@ func runCommandLoop(widget *Widget) {
cmd := exec.Command(widget.settings.cmd, widget.settings.args...)
cmd.Env = widget.environment()
f, err := pty.Start(cmd)
// The command has exited, print any error messages
if err != nil {
panic(err)
widget.handleError(err)
}

io.Copy(widget.buffer, f)
// The command has exited, print any error messages
_, err = io.Copy(widget.buffer, f)
if err != nil {
widget.m.Lock()
_, writeErr := widget.buffer.WriteString(err.Error())
if writeErr != nil {
return
}
widget.m.Unlock()
widget.handleError(err)
}
widget.redrawChan <- true
}
}

func (widget *Widget) handleError(err error) {
widget.m.Lock()
_, writeErr := widget.buffer.WriteString(err.Error())
if writeErr != nil {
return
}
widget.m.Unlock()
}

func redrawLoop(widget *Widget) {
for {
widget.Redraw(widget.content)
Expand Down

0 comments on commit c0ef9bd

Please sign in to comment.