Skip to content

Commit 4f2b63f

Browse files
committed
Std streams output funcs NoReset-versions
1 parent 313e26d commit 4f2b63f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

handlers.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,33 @@ func Log(err error) error {
8181
_ = handler.LogOutput(lvl, err.Error())
8282
return err
8383
}
84+
85+
// StderrNoReset is a built-in helper to use with Handle and Catch. It prints
86+
// the error to stderr. If you need to reset err value use Stderr instead.
87+
//
88+
// You can use it like this:
89+
//
90+
// func myFunction() {
91+
// defer err2.Handle(err2.Noop, err2.StderrNoReset)
92+
func StderrNoReset(err error) error {
93+
if err == nil {
94+
return nil
95+
}
96+
fmt.Fprintln(os.Stderr, err.Error())
97+
return nil
98+
}
99+
100+
// StdoutNoReset is a built-in helper to use with Handle and Catch. It prints
101+
// the error to stdout.
102+
//
103+
// You can use it like this:
104+
//
105+
// func main() {
106+
// defer err2.Catch(err2.StdoutNoReset)
107+
func StdoutNoReset(err error) error {
108+
if err == nil {
109+
return nil
110+
}
111+
fmt.Fprintln(os.Stdout, err.Error())
112+
return nil
113+
}

0 commit comments

Comments
 (0)