Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

nilerror Build Status Go Reference

Provides a River hook for detecting a common accidental Go problem where a nil struct value is wrapped in a non-nil interface value. This commonly causes trouble with the error interface, where an unintentional non-nil error is returned. For example:

func returnsError() error {
    var p *MyError = nil
    if bad() {
        p = ErrBad
    }
    return p // Will always return a non-nil error.
}

See https://go.dev/doc/faq#nil_error.

See example_hook_test.go for usage details.

Options

The hook supports these options:

hook := nilerror.NewHook(&HookConfig{
    Suppress: true,
})
  • Suppress: Causes the hook to suppress detected nil struct values wrapped in non-nil error interface values and produce warning logging instead.