Skip to content

tico8/lerrors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lerrors

Package lerrors provides labeled error for handling. labeled error is based on Go1.13 errors.

go get github.com/tico8/lerrors

import (
    "errors"
    le "github.com/tico8/lerrors"
)

var ErrNotFound = errors.New("not found")

func main() {
	book, err := Find("golang")
	if errors.Is(err, ErrNotFound) {
		fmt.Printf("err: %+v", err) // error details
		// ....
	}

}

func Find(id string) (*Book, error) {
	b, err := otherpkg.Find(id)
	if err != nil && otherpkg.IsErrNotFound(err) {
		return nil, le.Wrap(err, ErrNotFound)
	}

	return b, nil
}

About

create labeled error

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages