Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

chrisdoherty4/nilerr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nilerr 🤦

Nil pointers are an unfortunate reality in Go. Defining a nil error in projects repeatedly is cumbersome. This package offers a standard nil error type with some utility functions - nothing more, nothing less.

func Foo(b *Bar) error {
    if b == nil {
        return nilerr.New("b")
    }
}

func main() {
    err := Foo(nil)

    // True
    if nilerr.Is(err) { ... }

    // True
    if errors.Is(err, nilerr.E) { ... }

    // Prints "b is nil"
    fmt.Println(err)
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages