|
|
|
|
|
by randomdata
1035 days ago
|
|
Its flaws or merits aside, when you have no other useful context to add to the error, that's precisely what Errorf is for. func bar() error {
err := baz.Transmogrify()
return fmt.Errorf("transmogrify: %w", err)
}
func foo() error {
err := bar()
return fmt.Errorf("bar: %w", err)
}
func main() {
err := foo()
fmt.Printf("foo: %v", err)
// foo: bar: transmogrify: not found
}
There's your callstack, without the cost of carrying around the actual callstack. |
|