gum/internal/exit/exit.go
Carlos Alexandro Becker c868aa1c6c
fix(confirm,choose,file,input): timeout handling (#718)
* fix(confirm,choose,file,input): timeout handling

- some fields were not actually using the `--timeout` value
- some fields had different behavior when a timeout did occur. On this
  matter, it seems to me the best way forward is to specifically say it
  timed out, and after how long
- added exit status 124 (copied from `timeout` from coreutils) (fixes #684)

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* Update main.go

Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>

* Update internal/exit/exit.go

Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>

* fix: improve

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: stderr

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
2024-11-18 10:49:15 -03:00

26 lines
552 B
Go

package exit
import (
"errors"
"fmt"
"time"
"github.com/charmbracelet/huh"
)
// StatusTimeout is the exit code for timed out commands.
const StatusTimeout = 124
// StatusAborted is the exit code for aborted commands.
const StatusAborted = 130
// ErrAborted is the error to return when a gum command is aborted by Ctrl+C.
var ErrAborted = huh.ErrUserAborted
// Handle handles the error.
func Handle(err error, d time.Duration) error {
if errors.Is(err, huh.ErrTimeout) {
return fmt.Errorf("%w after %s", huh.ErrTimeout, d)
}
return err
}