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

Add SkipCaller(int) to support helper function around errtrace #70

Closed
RobertoMontagna opened this issue Dec 9, 2023 · 8 comments · Fixed by #108
Closed

Add SkipCaller(int) to support helper function around errtrace #70

RobertoMontagna opened this issue Dec 9, 2023 · 8 comments · Fixed by #108
Labels
enhancement New feature or request

Comments

@RobertoMontagna
Copy link

Absolutely not a priority ;)

Quoting: "It's important that the errtrace.Wrap function is called inside the same function that's actually returning the error. A helper function will not suffice."

It will be nice to be able to support helper functions, and mutating the idea from zap.Logger (AddSkipCaller) it should be possible.

@abhinav abhinav added the enhancement New feature or request label Dec 10, 2023
@abhinav
Copy link
Contributor

abhinav commented Dec 10, 2023

Hey, thanks for the issue!
This is definitely possible on the safe path, but much more difficult on the unsafe path.
If there's need for this functionality, we could probably change the unsafe path to fall back to the slow path if skip > 0.

@RobertoMontagna
Copy link
Author

Well, it will be a nice to have, but I don't think it is a must to have functionality.
Anyway thanks for taking it in consideration.

Checking the performance comparison, with the safe approach errtrace will still be comparable with FmtErrorf... so much slower but still (I think) a more than acceptable compromise... and anyway there are no free lunch :)

@abhinav
Copy link
Contributor

abhinav commented Dec 15, 2023

Thanks! I think this is a valid feature request, and I do think we should do it at some point.
It allows folks to write helpers for error building use cases that we haven't accounted for.
(e.g., if we didn't include errtrace.New, someone couldn't write their own errors.New wrapper that has the correct positioning.)

Out of curiosity, did you have a specific case where you were hoping to use this ability?

@RobertoMontagna
Copy link
Author

RobertoMontagna commented Dec 16, 2023

I'm just adopting errtrace, so in total honesty I don't have any real use case yet, everything is still a WIP.
I'll most probably work on something around the lines of adding the trace plus a string/annotation/extra value to simplify the life of other users

for example (or something something around this lines):
return errtracePlus.wrap(err, <format>, args ...any)

or the capability to join 2 or more errors and add the trace.

Note: I'm not join to call it errtracePlus ;)

The overall point is to make the life as easy as possible to my collegues to lower the entry bar for adoption.

@theFong
Copy link

theFong commented Jan 25, 2024

Wanted to double down on this feature. We had implemented something similar to this package but were looking to replace it with this by swapping the functions. We would need a way for skip to be implemented since our package would wrap errtrace.

@abhinav
Copy link
Contributor

abhinav commented Jan 25, 2024

@theFong Thanks for dropping that in. I think more data points on this issue helps.

I'm curious about the wrappers: if you're implementing your own wrappers, are you not auto-instrumenting your code? While that's not absolutely required for errtrace, we were under the impression that that was highly convenient.

@theFong
Copy link

theFong commented Jan 26, 2024

I did see the automatic instrumentation feature(should try it out). But I don't like the idea of having to review the diff across our entire codebase haha. Maybe I misunderstood how this feature works.

We already have a helper wrap function implemented. Our helper api accepts a string(s) and want to keep that functionality by appending it to the error string.
func WrapAndTrace(err error, messages ...string) error

@theFong
Copy link

theFong commented Jan 26, 2024

Wanted to follow up here. We've ended up adopting errtrace with manual instrumentation and have simply refactored out codebase to use Errorf when adding a message to the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants