mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-09 07:02:29 +08:00
feat: add XError to support more contextual error handling
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
// ---------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user