Skip to content

Golang | Errors | Decoration #94

@deoren

Description

@deoren

From Go 1.13:

return fmt.Errorf("unique error message: %w, err)

From third-party pkg/errors package:

import (
  // other imports here
  "github.com/pkg/errors"
)

return errors.Wrap(err, "unique error message")

Paraphrased explanation (I had a hard time keeping up and don't have enough time to properly replay/annotate):

You add your unique message, then you extend the actual error. Then when something goes wrong you can look at your unique message and it will tell you the "where", and the original message is the "why".

refs GopherCon 2019: Marwan Sulaiman - Handling Go Errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions