From f1cbf9c85d2bade571b4716dfb1e93f3c96b309f Mon Sep 17 00:00:00 2001 From: Foil-hat-guy Date: Thu, 8 May 2025 20:42:53 +0300 Subject: [PATCH] Upgraded do to 1.23 to get errors.Join function --- error.go | 26 -------------------------- go.mod | 6 +++--- real.go | 11 ++++++----- stty.go | 7 ++++--- 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/error.go b/error.go index 56d3a5e..7890753 100644 --- a/error.go +++ b/error.go @@ -4,32 +4,6 @@ import ( "fmt" ) -func filterNilErrors(errs []error) (notNilErrs []error) { - for _, err := range errs { - if err != nil { - notNilErrs = append(notNilErrs, err) - } - } - return notNilErrs -} - -func Join(errs ...error) (result error) { - errs = filterNilErrors(errs) - if len(errs) == 0 { - return nil - } - - for index, err := range errs { - if index == 0 { - result = err - } else { - result = fmt.Errorf("%w: %v", result, err) - } - - } - return result -} - func ERR_NOT_TTY() error { return fmt.Errorf("File is not a tty") } diff --git a/go.mod b/go.mod index 746faae..afb17b8 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ module code.foilhatguy.casa/pub/stty -go 1.19 +go 1.23 require ( - golang.org/x/sys v0.15.0 // indirect - golang.org/x/term v0.15.0 // indirect + golang.org/x/sys v0.15.0 + golang.org/x/term v0.15.0 ) diff --git a/real.go b/real.go index 1354863..e7bcc0e 100644 --- a/real.go +++ b/real.go @@ -1,8 +1,9 @@ package stty -import( - "os/exec" - "fmt" +import ( + "errors" + "fmt" + "os/exec" ) type real struct { @@ -12,7 +13,7 @@ func (r *real) SetBaudRate(portPath string, baudrate int) error { setBaudRateCMD := exec.Command("stty", "-F", portPath, fmt.Sprint(baudrate)) _, err := setBaudRateCMD.Output() if err != nil { - return Join(ERR_SET_BAUDRATE_FAILED(), err) + return errors.Join(ERR_SET_BAUDRATE_FAILED(), err) } return nil } @@ -39,7 +40,7 @@ func (r *real) TestBaudRate(portPath string, baudrate int) error { newBaudRate, err := r.CheckBaudRate(portPath) if err != nil { - return Join(ERR_CHECK_BAUDRATE_FAILED(), err) + return errors.Join(ERR_CHECK_BAUDRATE_FAILED(), err) } if newBaudRate == baudrate { diff --git a/stty.go b/stty.go index 3ce1977..02fac00 100644 --- a/stty.go +++ b/stty.go @@ -1,6 +1,7 @@ package stty import ( + "errors" "fmt" "os" "os/exec" @@ -25,7 +26,7 @@ func init() { checkSttyCMD := exec.Command("stty", "--version") sttyOutput, err := checkSttyCMD.Output() if err != nil || len(sttyOutput) == 0 { - cmd = &dummy{Join(ERR_STTY_MISSING(),err)} + cmd = &dummy{errors.Join(ERR_STTY_MISSING(),err)} } cmd = &real{} } @@ -33,13 +34,13 @@ func init() { func ValidateTtyFile(filepath string) error { file, err := os.Open(filepath) if err != nil { - return Join(ERR_CANNOT_OPEN_FILE(), fmt.Errorf(err.Error())) + return errors.Join(ERR_CANNOT_OPEN_FILE(), fmt.Errorf(err.Error())) } defer file.Close() err = unix.Access(filepath, unix.W_OK) if err != nil { - return Join(ERR_NO_WRITE_ACCESS(), err) + return errors.Join(ERR_NO_WRITE_ACCESS(), err) } if term.IsTerminal(int(file.Fd())) {