Skip to content

Go package for setting and retrieving contextual information using error objects

License

Notifications You must be signed in to change notification settings

levenlabs/errctx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

errctx

The errctx package allows for setting and retrieving contextual information using error objects.

Usage

err := errors.New("something bad happened")
// set the userID that caused this error
return errctx.Set(err, "userID", userID)

Later on you can get the userID back:

userID, ok := errctx.Get(err, "userID").(int64)

If you want to check the original error object:

if errors.Is(err, mgo.ErrNotFound) {

}

Additionally, if you want to store the source of the original error you can use Mark and Line:

err := errors.New("something bad happened")
// store the filename and line number where Mark was called
return errctx.Mark(err)

Later you can use Line to get the filename:line where Mark was first called:

fileLine, ok := errctx.Line(err)

About

Go package for setting and retrieving contextual information using error objects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages