forked from SAP/jenkins-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
76 lines (67 loc) · 1.7 KB
/
errors.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package log
// ErrorCategory defines the category of a pipeline error
type ErrorCategory int
// Error categories which allow categorizing failures
const (
ErrorUndefined ErrorCategory = iota
ErrorBuild
ErrorCompliance
ErrorConfiguration
ErrorCustom
ErrorInfrastructure
ErrorService
ErrorTest
)
var errorCategory ErrorCategory = ErrorUndefined
var fatalError []byte
func (e ErrorCategory) String() string {
return [...]string{
"undefined",
"build",
"compliance",
"config",
"custom",
"infrastructure",
"service",
"test",
}[e]
}
// ErrorCategoryByString returns the error category based on the category text
func ErrorCategoryByString(category string) ErrorCategory {
switch category {
case "build":
return ErrorBuild
case "compliance":
return ErrorCompliance
case "config":
return ErrorConfiguration
case "custom":
return ErrorCustom
case "infrastructure":
return ErrorInfrastructure
case "service":
return ErrorService
case "test":
return ErrorTest
}
return ErrorUndefined
}
// SetErrorCategory sets the error category
// This can be used later by calling log.GetErrorCategory()
// In addition it will be used when exiting the program with
// log.FatalError(err, message)
func SetErrorCategory(category ErrorCategory) {
errorCategory = category
}
// GetErrorCategory retrieves the error category which is currently known to the execution of a step
func GetErrorCategory() ErrorCategory {
return errorCategory
}
// SetFatalErrorDetail sets the fatal error to be stored
func SetFatalErrorDetail(error []byte) {
fatalError = error
}
// GetFatalErrorDetail retrieves the error which is currently known to the execution of a step
func GetFatalErrorDetail() []byte {
return fatalError
}