Errors

Go Reference

Golang package to create constant sentinel errors with errors.Is support.

Install

go get github.com/nicolasparada/go-errs

Usage

You can create your own constant sentinel errors as if they were a string.

package myapp

import (
    errs "github.com/nicolasparada/go-errs"
)

const (
    ErrInvalidEmail = errs.InvalidArgumentError("myapp: invalid email")
)

You can use errors.Is to check if your error is known.

package main

import (
    "errors"
    "fmt"

    "myapp"
    errs "github.com/nicolasparada/go-errs"
)

func main() {
    ok := errors.Is(myapp.ErrInvalidEmail, errs.ErrInvalidArgument)
    fmt.Println(ok)
    // Output: true
}

GitHub

View Github