Repository navigation
Expand file tree
/
Copy patherrors.go
More file actions
70 lines (55 loc) · 1.36 KB
/
Copy patherrors.go
File metadata and controls
70 lines (55 loc) · 1.36 KB
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
package godexer
import (
"reflect"
"github.com/go-extras/errors"
)
type CommandAwareError struct {
err error
cmd Command
variables map[string]any
}
func NewCommandAwareError(err error, cmd Command, variables map[string]any) *CommandAwareError {
varsCopy := make(map[string]any, len(variables))
for k, v := range variables {
varsCopy[k] = v
}
result := &CommandAwareError{
err: err,
cmd: cmd,
variables: varsCopy,
}
return result
}
func (*CommandAwareError) getType(myvar any) string {
t := reflect.TypeOf(myvar)
if t.Kind() == reflect.Ptr {
return t.Elem().Name()
}
return t.Name()
}
func (e *CommandAwareError) Cause() error {
return e.err
}
func (e *CommandAwareError) Variables() map[string]any {
return e.variables
}
func (e *CommandAwareError) Command() Command {
return e.cmd
}
func (e *CommandAwareError) Error() string {
stepName := e.cmd.GetStepName()
commandID := 0
if dicmd, ok := e.cmd.(DebugInfoer); ok {
di := dicmd.DebugInfo()
if di != nil {
commandID = di.ID
}
}
if commandID == 0 {
return errors.Wrapf(e.err, "command failed (stepName=%s, commandType=%s)", stepName, e.getType(e.cmd)).Error()
}
return errors.Wrapf(e.err, "command failed (stepName=%s, commandId=%d, commandType=%s)", stepName, commandID, e.getType(e.cmd)).Error()
}
func (e *CommandAwareError) Unwrap() error {
return e.err
}