Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Error.New for errors.Wrap #382

Closed
4 tasks done
ethanfrey opened this issue Mar 6, 2019 · 0 comments · Fixed by #402
Closed
4 tasks done

Deprecate Error.New for errors.Wrap #382

ethanfrey opened this issue Mar 6, 2019 · 0 comments · Fixed by #402
Assignees

Comments

@ethanfrey
Copy link
Contributor

ethanfrey commented Mar 6, 2019

Based on #368

Error.New method provides the same functionality as errors.Wrap function (it is an alias). I think that Wrap function provides a better information of what the implementation is doing and what the result is.
errors.Wrap cannot be removed because this is the only way to wrap an error. Error.New method cannot be used for this.

I also find the Newf functionality very handy (it came up after lots of tedious error writing), so I would propose:

  • Add errors.Wrapf(), which is errors.Wrap and fmt.Sprintf combines (like Newf is). done
  • Convert all usages of ErrXyz.New("foo") to errors.Wrap(ErrXyz, "foo")
  • Convert all usages of ErrXyz.Newf("foo %s", ...) to errors.Wrapf(ErrXyz, "foo %s", ...)
  • Remove Error.New and Error.Newf

Ideally the two conversion steps can be automated with a clever regexp

@husio husio self-assigned this Mar 13, 2019
husio added a commit that referenced this issue Mar 14, 2019
Use `errors.Wrap` and `errors.Wrapf` insteand of `New` and `Newf`
methods. This is a removal of a syntatic sugar.

Using `Wrap` function instead of method allows for consistent usage of
error wrapping. Before it could have been confusing when to use `Wrap`
and when `New`.

resolve #382
husio added a commit that referenced this issue Mar 14, 2019
Use `errors.Wrap` and `errors.Wrapf` insteand of `New` and `Newf`
methods. This is a removal of a syntatic sugar.

Using `Wrap` function instead of method allows for consistent usage of
error wrapping. Before it could have been confusing when to use `Wrap`
and when `New`.

resolve #382
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants