-
Notifications
You must be signed in to change notification settings - Fork 1
/
failure.go
60 lines (51 loc) · 1.69 KB
/
failure.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
package action
import (
"encoding/json"
)
type (
// Type used to identify the cause of the failure
failureCause string
// Detail of a playbook execution failure
playBookFailureDetail struct {
// The name of the playbook
Playbook string
// The component holding the playbook
Component string
// The ansible return code
Code int
}
)
const (
notImplementedFailure failureCause = "NotImplemented"
codeFailure failureCause = "Code"
descriptorFailure failureCause = "Descriptor"
playBookFailure failureCause = "PlayBook"
)
// FailsOnNotImplemented allows to create a failure on an execution step
// because of a missing implementation
var FailsOnNotImplemented = failOn(notImplementedFailure)
// FailsOnCode allows to create a failure on an execution step
// because of an error returned by ekara, other than errors generated
// by the processing of the descriptor of by a playbook execution
var FailsOnCode = failOn(codeFailure)
// FailsOnDescriptor allows to create a failure on an execution step
// because of an invalid descriptor
var FailsOnDescriptor = failOn(descriptorFailure)
// FailsOnPlaybook allows to create a failure on an execution step
// because of an error return by a playbook execution
var FailsOnPlaybook = failOn(playBookFailure)
func failOn(fc failureCause) func(sr *StepResult, err error, detail string, content interface{}) {
return func(sr *StepResult, err error, detail string, content interface{}) {
sr.FailureCause = fc
sr.error = err
if err != nil {
sr.ErrorMessage = err.Error()
}
sr.ReadableMessage = detail
sr.Status = stepStatusFailure
if content != nil {
bs, _ := json.Marshal(content)
sr.RawContent = string(bs)
}
}
}