Last active
January 11, 2019 21:17
-
-
Save tonyyang-svail/a573de68c10897890acb778f3f170c49 to your computer and use it in GitHub Desktop.
This file contains 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
package main | |
import ( | |
"fmt" | |
"github.com/pkg/errors" | |
) | |
func bar() error { | |
return errors.Wrap(fmt.Errorf("barError"), "bar") | |
} | |
func foo() error { | |
return bar() | |
} | |
type stackTracer interface { | |
StackTrace() errors.StackTrace | |
} | |
func main() { | |
err := foo() | |
if err, ok := err.(stackTracer); ok { | |
for _, f := range err.StackTrace() { | |
fmt.Printf("%+s:%d\n", f, f) | |
} | |
} | |
} |
Author
tonyyang-svail
commented
Jan 11, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment