-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Description
When using err2.Handle(&err)
in functions whose names contain the substring "handle" (case-insensitive), error annotations show incorrect function names in the error chain. Instead of displaying the actual function names, it shows main: main:
repeatedly.
Steps to Reproduce
package main
import (
"fmt"
"github.com/lainio/err2"
"github.com/lainio/err2/try"
)
func FirstHandle() (err error) {
defer err2.Handle(&err)
try.To(SecondHandle())
return nil
}
func SecondHandle() (err error) {
defer err2.Handle(&err)
try.To(fmt.Errorf("my error"))
return nil
}
func main() {
err := FirstHandle()
fmt.Printf("Final error: %v\n", err)
}
Current (incorrect) output:
Final error: main: main: my error
Expected output:
Final error: first handle: second handle: my error
Root Cause
The isFuncAnchor
function in internal/debug/debug.go
uses simple substring matching to find "Handle" in stack traces. This causes it to incorrectly match user functions like "FirstHandle" or "MyHandler" when searching for the err2.Handle
function, leading to incorrect stack trace parsing and error annotation.
Workaround
Currently, the only workaround is to avoid using "handle" (case-insensitive) as a substring in function names when using err2.Handle
. Or to annotate errors manually.
Environment
- Go version: 1.24.4
- err2 version: v1.2.2