-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2h.go
49 lines (40 loc) · 934 Bytes
/
e2h.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
Package e2h its the package of the Enhanced Error Handling module
*/
package e2h
import (
"fmt"
)
// ExtendedError interface
type EnhancedError interface {
Error() string
Cause() error
Stack() []StackDetails
}
// Entity details with detailed info
type StackDetails struct {
File string
Line int
FuncName string
Message string
}
// Entity enhancedError with error and details
type enhancedError struct {
err error
stack []StackDetails
}
// This function returns the Error string plus the origin custom message (if exists)
func (e *enhancedError) Error() string {
if len(e.stack[0].Message) > 0 {
return fmt.Sprintf("%s: %s", e.err.Error(), e.stack[0].Message)
}
return e.err.Error()
}
// This function returns the source error
func (e *enhancedError) Cause() error {
return e.err
}
// This function returns the callstack details
func (e *enhancedError) Stack() []StackDetails {
return e.stack
}