Skip to content

Commit

Permalink
Stdnull added
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio committed Jan 3, 2024
1 parent c18ffb4 commit ed379b0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion err2.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ var (
// same error. These error are mainly for that purpose.
ErrNotRecoverable = errors.New("cannot recover")
ErrRecoverable = errors.New("recoverable")

// Stdnull is helper variable for io.Writer need e.g. err2.SetLogTracer in
// cases you don't want to use automatic log writer, i.e. LogTracer == nil.
// It's usually used to change how the Catch works, e.g., in CLI apps.
Stdnull = &nullDev{}
)

// Handle is the general purpose error handling function. What makes it so
Expand Down Expand Up @@ -116,7 +121,11 @@ func Handle(err *error, a ...any) {
//
// The preceding line catches the errors and panics and prints an annotated
// error message about the error source (from where the error was thrown) to the
// currently set log.
// currently set log. Note, when log stream isn't set, the standard log is used.
// It can be bound to, e.g., glog. And if you want to suppress automatic logging
// use the following setup:
//
// err2.SetLogTracer(err2.Stdnull)
//
// The next one stops errors and panics, but allows you handle errors, like
// cleanups, etc. The error handler function has same signature as Handle's
Expand Down Expand Up @@ -228,6 +237,10 @@ func Err(f func(err error)) func(error) error {
}
}

type nullDev struct{}

func (nullDev) Write([]byte) (int, error) { return 0, nil }

func doTrace(err error) {
if err == nil || err.Error() == "" {
return
Expand Down

0 comments on commit ed379b0

Please sign in to comment.