feat: add XError to support more contextual error handling

This commit is contained in:
dudaodong committed 2023-02-14 16:32:57 +08:00
1 parent 57bd64cae7
commit d0260b2841
4 files changed
+305 -12

No files matched your search

+20 -1
View File
@@ -16,7 +16,26 @@ import (
type Stack struct {
Func string `json:"func"`
File string `json:"file"`
Line string `json:"line"`
Line int `json:"line"`
}
// Stacks returns stack trace array generated by pkg/errors
func (e *XError) Stacks() []*Stack {
resp := make([]*Stack, len(*e.stack))
for i, st := range *e.stack {
f := frame(st)
resp[i] = &Stack{
Func: f.name(),
File: f.file(),
Line: f.line(),
}
}
return resp
}
// StackTrace returns stack trace which is compatible with pkg/errors
func (e *XError) StackTrace() StackTrace {
return e.stack.StackTrace()
}
// ---------------------------------------