Wrapping Go errors with a caller name and other helpers
caller.Wrap(err) error
- wrap error with caller name. Example
package mypkg
import "github.com/spirin/caller"
func myFunc() error {
err := doSmth()
if err != nil {
// "mypkg.myFunc: some err"
return caller.Wrap(err)
}
...
}
caller.WrapPackage(err) error
- wrap error with caller package name. Example: "http: some err"
package mypkg
import "github.com/spirin/caller"
func myFunc() error {
err := doSmth()
if err != nil {
// "mypkg: some err"
return caller.WrapPackage(err)
}
...
}
caller.Name() string
- get caller name, e.g., "caller.testNameObj.Fn"
caller.NameFull() string
- get caller full name, e.g., "testNameFullObj.Fn @ github.com/spirin/caller"
caller.Package() string
- get caller package name, e.g., "caller"