Skip to content

Golang | Errors | Decoration #94

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions