1
0
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:
dudaodong
2023-02-14 16:32:57 +08:00
parent 57bd64cae7
commit d0260b2841
4 changed files with 305 additions and 12 deletions

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()
}
// ---------------------------------------