Fix: Error annotations fail when user functions contain "Handle" in their name #31
+121
−1
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