errors icon indicating copy to clipboard operation
errors copied to clipboard

fix: return new withStack directly so AddStack() is not added to the stack

Open olistrik opened this issue 1 year ago • 0 comments

While I understand the desire to not re-implement WithStack(), by wrapping it in AddStack() the AddStack() function appears on the stack trace, unlike WithStack() which does not because callers() aliases callersSkip(4).

Before:

example error
github.com/pingcap/errors.AddStack
	.../vendor/github.com/pingcap/errors/errors.go:174
main.bar
	.../main.go:18
main.foo
	.../main.go:14
main.main
	.../main.go:22
runtime.main
	/share/go/src/runtime/proc.go:267
runtime.goexit
	/share/go/src/runtime/asm_amd64.s:1650

After:

example error
main.bar
	.../main.go:18
main.foo
	.../main.go:14
main.main
	.../main.go:22
runtime.main
	/share/go/src/runtime/proc.go:267
runtime.goexit
	/share/go/src/runtime/asm_amd64.s:1650

Another solution would be to create a private function that both call, and up the skipCallers to 5, but they're such simple functions I dont think its necessary.

olistrik avatar Apr 12 '24 11:04 olistrik