|
33 | 33 | // same error. These error are mainly for that purpose.
|
34 | 34 | ErrNotRecoverable = errors.New("cannot recover")
|
35 | 35 | ErrRecoverable = errors.New("recoverable")
|
| 36 | + |
| 37 | + // Stdnull is helper variable for io.Writer need e.g. err2.SetLogTracer in |
| 38 | + // cases you don't want to use automatic log writer, i.e. LogTracer == nil. |
| 39 | + // It's usually used to change how the Catch works, e.g., in CLI apps. |
| 40 | + Stdnull = &nullDev{} |
36 | 41 | )
|
37 | 42 |
|
38 | 43 | // Handle is the general purpose error handling function. What makes it so
|
@@ -116,7 +121,11 @@ func Handle(err *error, a ...any) {
|
116 | 121 | //
|
117 | 122 | // The preceding line catches the errors and panics and prints an annotated
|
118 | 123 | // error message about the error source (from where the error was thrown) to the
|
119 |
| -// currently set log. |
| 124 | +// currently set log. Note, when log stream isn't set, the standard log is used. |
| 125 | +// It can be bound to, e.g., glog. And if you want to suppress automatic logging |
| 126 | +// use the following setup: |
| 127 | +// |
| 128 | +// err2.SetLogTracer(err2.Stdnull) |
120 | 129 | //
|
121 | 130 | // The next one stops errors and panics, but allows you handle errors, like
|
122 | 131 | // cleanups, etc. The error handler function has same signature as Handle's
|
@@ -228,6 +237,10 @@ func Err(f func(err error)) func(error) error {
|
228 | 237 | }
|
229 | 238 | }
|
230 | 239 |
|
| 240 | +type nullDev struct{} |
| 241 | + |
| 242 | +func (nullDev) Write([]byte) (int, error) { return 0, nil } |
| 243 | + |
231 | 244 | func doTrace(err error) {
|
232 | 245 | if err == nil || err.Error() == "" {
|
233 | 246 | return
|
|
0 commit comments