chore(lint): wrap various TTY-related errors

This commit is contained in:
Christian Rocha 2023-07-06 16:20:36 -04:00 committed by Christian Muehlhaeuser
parent ea7ceb7f38
commit 5bc2504690
2 changed files with 9 additions and 5 deletions

7
tty.go
View File

@ -2,6 +2,7 @@ package tea
import ( import (
"errors" "errors"
"fmt"
"io" "io"
"os" "os"
"time" "time"
@ -21,7 +22,7 @@ func (p *Program) initTerminal() error {
if p.console != nil { if p.console != nil {
err = p.console.SetRaw() err = p.console.SetRaw()
if err != nil { if err != nil {
return err return fmt.Errorf("error entering raw mode: %w", err)
} }
} }
@ -48,7 +49,7 @@ func (p *Program) restoreTerminalState() error {
if p.console != nil { if p.console != nil {
err := p.console.Reset() err := p.console.Reset()
if err != nil { if err != nil {
return err return fmt.Errorf("error restoring terminal state: %w", err)
} }
} }
@ -60,7 +61,7 @@ func (p *Program) initCancelReader() error {
var err error var err error
p.cancelReader, err = cancelreader.NewReader(p.input) p.cancelReader, err = cancelreader.NewReader(p.input)
if err != nil { if err != nil {
return err return fmt.Errorf("error creating cancelreader: %w", err)
} }
p.readLoopDone = make(chan struct{}) p.readLoopDone = make(chan struct{})

View File

@ -4,6 +4,7 @@
package tea package tea
import ( import (
"fmt"
"os" "os"
"github.com/containerd/console" "github.com/containerd/console"
@ -28,7 +29,9 @@ func (p *Program) initInput() error {
// program exits. // program exits.
func (p *Program) restoreInput() error { func (p *Program) restoreInput() error {
if p.console != nil { if p.console != nil {
return p.console.Reset() if err := p.console.Reset(); err != nil {
return fmt.Errorf("error restoring console: %w", err)
}
} }
return nil return nil
} }
@ -36,7 +39,7 @@ func (p *Program) restoreInput() error {
func openInputTTY() (*os.File, error) { func openInputTTY() (*os.File, error) {
f, err := os.Open("/dev/tty") f, err := os.Open("/dev/tty")
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("could not open a new TTY: %w", err)
} }
return f, nil return f, nil
} }