errors icon indicating copy to clipboard operation
errors copied to clipboard

How to use NewNotFound() properly

Open skreutzberger opened this issue 2 years ago • 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?

skreutzberger avatar Oct 10 '23 14:10 skreutzberger