Fix: Error annotations fail when user functions contain "Handle" in their name#31
Closed
rgeraskin wants to merge 1 commit intolainio:masterfrom
Closed
Fix: Error annotations fail when user functions contain "Handle" in their name#31rgeraskin wants to merge 1 commit intolainio:masterfrom
rgeraskin wants to merge 1 commit intolainio:masterfrom
Conversation
…tions with 'Handle' substring
Owner
|
Thank you! I really appreciate your work. However, I'm a little confused with the fix, and that's why I have created a separate branch that fixes the bug just by changing one line in the file The complete fix can be seen in the branch I apologize for not having had time to comment on this earlier. |
Author
|
Thanks! I checked out your branch. In my opinion, your solution is much simpler and cleaner, and it resolves the issue. Also, I see that the same tests as for this PR pass for your branch. So I see no reason to accept this PR🙂 Looking forward to your fix being merged into master. Thanks! |
Owner
|
Closing this. Fix done in #33. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
err2.Handlestack anchors are matched only for theerr2package (including versioned modules), not for user functions likeFirstHandleormain.Handle.Background
When using
err2.Handle(&err)inside functions whose names contain “handle”, error annotations showed incorrect function names (e.g.,main: main:). See Bug: Error annotations fail when user functions contain "Handle" in their name.Changes
isFuncAnchorlogic inerr2/internal/debug/debug.go:err2, or a version tokenvNpreceded byerr2(supports.../err2/v2.Handle).strings.Index, no regex construction.isErr2BeforeDotto validate the package token.handlerlogic; only stack parsing is updated.Why this approach
err2.Handleand versionederr2/vN.Handle./err2/anywhere before).strings.LastIndex).Tests
Added/extended cases in
err2/internal/debug/debug_test.goto cover:err2.Handle(...)github.com/lainio/err2.Handle(...)github.com/lainio/err2/v2.Handle(...)github.com/lainio/err2/v10.Handle(...)main.Handle(...)mypackage.Handle(...)main.FirstHandle(...)github.com/myco/err2/mypackage.Handle(...)Example
Before:
Final error: main: main: my errorAfter:
Final error: first handle: second handle: my errorCompatibility and Performance
err2stack parsing.Risks
err2-scoped packages; tests cover edge cases.Links