Skip to content

Commit

Permalink
Std streams output funcs NoReset-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio committed Feb 20, 2024
1 parent 313e26d commit 4f2b63f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,33 @@ func Log(err error) error {
_ = handler.LogOutput(lvl, err.Error())
return err
}

// StderrNoReset is a built-in helper to use with Handle and Catch. It prints
// the error to stderr. If you need to reset err value use Stderr instead.
//
// You can use it like this:
//
// func myFunction() {
// defer err2.Handle(err2.Noop, err2.StderrNoReset)
func StderrNoReset(err error) error {
if err == nil {
return nil
}
fmt.Fprintln(os.Stderr, err.Error())
return nil
}

// StdoutNoReset is a built-in helper to use with Handle and Catch. It prints
// the error to stdout.
//
// You can use it like this:
//
// func main() {
// defer err2.Catch(err2.StdoutNoReset)
func StdoutNoReset(err error) error {
if err == nil {
return nil
}
fmt.Fprintln(os.Stdout, err.Error())
return nil
}

0 comments on commit 4f2b63f

Please sign in to comment.