Skip to content

How to use NewNotFound() properly #65

@skreutzberger

Description

@skreutzberger

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions