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

Feature: ability to automatically wrap errors? #8

Open
arp242 opened this issue Sep 21, 2017 · 1 comment
Open

Feature: ability to automatically wrap errors? #8

arp242 opened this issue Sep 21, 2017 · 1 comment

Comments

@arp242
Copy link

arp242 commented Sep 21, 2017

You frequently want to add a function call to errors, such as:

return fmt.Errorf("cannot parse %v: %v", input, err)

or:

return errors.Wrap(err)

It would be nice if you could do something like:

$ expanderr -wrap errors.Wrap err.go:#42
$ expanderr -wrap fmt.Errorf err.go:#42

Which would result in:

return fmt.Errorf(|err)
return errors.Wrap(|err)

The pipe is the location of the cursor; the location of that could be added in the -format json output.

I can take a look at this later if feel this would be a good addition.

@stapelberg
Copy link
Owner

The feature itself is welcome, but I’m not entirely sure yet about how it should look like:

I have to admit that I don’t have more experience with error-wrapping packages than the pure knowledge of github.com/pkg/errors’s existence. I know that there are others, and I don’t know whether they are all used the same way, or if there are multiple legit ways to use these packages.

Regarding your suggestion, I think adding errors.Wrap is fine, but just adding fmt.Errorf seems too brittle — I think we should make it fmt.Errorf("%v", err) at least.

I’m not sure how much customization is necessary/warranted here. I.e., would -wrap identify one of multiple pre-defined wrapping strategies? It seems like any kind of templating support would open a can of worms :)

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

No branches or pull requests

2 participants