Total Lines | 45 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | /* |
||
4 | package e2h |
||
5 | |||
6 | import ( |
||
7 | "fmt" |
||
8 | ) |
||
9 | |||
10 | // ExtendedError interface |
||
11 | type EnhancedError interface { |
||
12 | Error() string |
||
13 | Cause() error |
||
14 | Stack() []StackDetails |
||
15 | } |
||
16 | |||
17 | // Entity details with detailed info |
||
18 | type StackDetails struct { |
||
19 | File string |
||
20 | Line int |
||
21 | FuncName string |
||
22 | Message string |
||
23 | } |
||
24 | |||
25 | // Entity enhancedError with error and details |
||
26 | type enhancedError struct { |
||
27 | err error |
||
28 | stack []StackDetails |
||
29 | } |
||
30 | |||
31 | // This function returns the Error string plus the origin custom message (if exists) |
||
32 | func (e *enhancedError) Error() string { |
||
33 | |||
34 | 1 | if len(e.stack[0].Message) > 0 { |
|
35 | 1 | return fmt.Sprintf("%s: %s", e.err.Error(), e.stack[0].Message) |
|
36 | } |
||
37 | |||
38 | 1 | return e.err.Error() |
|
39 | } |
||
40 | |||
41 | // This function returns the source error |
||
42 | func (e *enhancedError) Cause() error { |
||
43 | 1 | return e.err |
|
44 | } |
||
45 | |||
46 | // This function returns the callstack details |
||
47 | func (e *enhancedError) Stack() []StackDetails { |
||
48 | 1 | return e.stack |
|
49 | } |
||
50 |