e2h.go   A
last analyzed

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
cc 4
eloc 23
dl 0
loc 45
ccs 5
cts 5
cp 1
crap 4
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A e2h.*enhancedError.Cause 0 2 1
A e2h.*enhancedError.Error 0 7 2
A e2h.*enhancedError.Stack 0 2 1
1
/*
2
Package e2h its the package of the Enhanced Error Handling module
3
*/
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