We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkg/errors#242
package main import ( "fmt" "github.com/pkg/errors" ) func main() { err := one() fmt.Printf("%+v\n", err) } func one() error { return errors.Wrap(two(), "call two error") } func two() error { return errors.Wrap(three(), "call three error") } func three() error { return errors.New("something error") }
可以看到每个 error 都带了调用栈,冗余信息比较多
something error main.three /home/anyh/Documents/golang/demo/errors_demo/main.go:23 main.two /home/anyh/Documents/golang/demo/errors_demo/main.go:19 main.one /home/anyh/Documents/golang/demo/errors_demo/main.go:15 main.main /home/anyh/Documents/golang/demo/errors_demo/main.go:10 runtime.main /usr/local/go/src/runtime/proc.go:250 runtime.goexit /usr/local/go/src/runtime/asm_amd64.s:1598 call three error main.two /home/anyh/Documents/golang/demo/errors_demo/main.go:19 main.one /home/anyh/Documents/golang/demo/errors_demo/main.go:15 main.main /home/anyh/Documents/golang/demo/errors_demo/main.go:10 runtime.main /usr/local/go/src/runtime/proc.go:250 runtime.goexit /usr/local/go/src/runtime/asm_amd64.s:1598 call two error main.one /home/anyh/Documents/golang/demo/errors_demo/main.go:15 main.main /home/anyh/Documents/golang/demo/errors_demo/main.go:10 runtime.main /usr/local/go/src/runtime/proc.go:250 runtime.goexit /usr/local/go/src/runtime/asm_amd64.s:1598
当然你可以仅在最底层的 error 包含 stack,中间函数调用直接 return,这样最顶层就没有冗余信息了
package main import ( "fmt" "github.com/pkg/errors" ) func main() { err := one() fmt.Printf("%+v\n", err) } func one() error { return two() } func two() error { return three() } func three() error { return errors.New("something error") }
something error main.three /home/anyh/Documents/golang/demo/errors_demo/main.go:23 main.two /home/anyh/Documents/golang/demo/errors_demo/main.go:19 main.one /home/anyh/Documents/golang/demo/errors_demo/main.go:15 main.main /home/anyh/Documents/golang/demo/errors_demo/main.go:10 runtime.main /usr/local/go/src/runtime/proc.go:250 runtime.goexit /usr/local/go/src/runtime/asm_amd64.s:1598
但是如果项目比较复杂,调用层级比较深的时候,不好保证
The text was updated successfully, but these errors were encountered:
No branches or pull requests
pkg/errors#242
可以看到每个 error 都带了调用栈,冗余信息比较多
当然你可以仅在最底层的 error 包含 stack,中间函数调用直接 return,这样最顶层就没有冗余信息了
但是如果项目比较复杂,调用层级比较深的时候,不好保证
The text was updated successfully, but these errors were encountered: