Skip to content

Commit

Permalink
Provide information about why context was cancelled on command fail
Browse files Browse the repository at this point in the history
  • Loading branch information
dantecatalfamo committed Sep 26, 2024
1 parent e02afc4 commit 6f234cd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions orbit/pkg/swiftdialog/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
var CommandFilePerms = fs.FileMode(0666)

var ErrKilled = errors.New("process killed")
var ErrWindowClosed = errors.New("window closed")

type SwiftDialog struct {
cancel context.CancelCauseFunc
Expand Down Expand Up @@ -104,7 +105,7 @@ func Create(ctx context.Context, swiftDialogBin string, options *SwiftDialogOpti
}
}
close(sd.done)
cancel(nil)
cancel(ErrWindowClosed)
}()

return sd, nil
Expand Down Expand Up @@ -161,7 +162,7 @@ func (s *SwiftDialog) Wait() (*SwiftDialogExit, error) {

func (s *SwiftDialog) sendCommand(command, arg string) error {
if err := s.context.Err(); err != nil {
return fmt.Errorf("could not send command: %w", err)
return fmt.Errorf("could not send command: %w", context.Cause(s.context))
}
// For some reason swiftDialog needs us to open and close the file
// to detect a new command, just writing to the file doesn't cause
Expand Down

0 comments on commit 6f234cd

Please sign in to comment.