pkg / errors

Simple error handling primitives
https://godoc.org/github.com/pkg/errors
BSD 2-Clause "Simplified" License
8.2k stars 697 forks source link

Wrapf: remove duplicated code #161

Closed grrtrr closed 6 years ago

grrtrr commented 6 years ago

Wrap and Wrapf have the same behaviour and nearly identical function bodies. This removes the duplicate code by expressing Wrapf in terms of Wrap.

grrtrr commented 6 years ago

This broke the test.

puellanivis commented 6 years ago

What went wrong here (I tried thinking about this before myself) was that the callers() call expects to be called directly from the Wrap/Wrapf function. When you are writing Wrapf in terms of Wrap, callers is now being called one deeper in the stack, which it fails to skip over, and thus this.

I’ve basically left all refactoring of the common code alone as a result, as any such work would have to include the callers() in the proper frame and 🤷‍♀️ at that point you’re overcomplicating the code just to remove some extremely simplistic code.

grrtrr commented 6 years ago

Thank you for the explanation. It was a good reminder to run tests first; they are well done.