juju/errors

How to use NewNotFound() properly

skreutzberger opened this issue · 0 comments

Hi,

I am frequently using NewNotFound() and NewBadRequest() in my model logic so that the receiving controller knows about the type of error using an if-statement with errors.Is(err, errors.NotFound) for example.

I just realized now that errors which were wrapped with NewNotFound() somehow have no file, line and function recorded which makes it harder to find the error location.

Here is an example:

err := errors.New("my error")
err = errors.NewNotFound(err, "first context")
println(errors.ErrorStack(err))
       
// returns the following which lacks the file, line and function
first context: my error

Am I using it wrong?