/
runner.go
49 lines (41 loc) · 1.05 KB
/
runner.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 jobs
import (
"context"
"fmt"
)
const ErrMissingDetails = "MissingDetails"
const ErrPreExecFailure = "PreExecutionFailure"
const ErrExecFailure = "ExecutionFailure"
const ErrPostExecFailure = "PostExecutionFailure"
// Runner has a Run method and runs a job
type Runner interface {
Run(ctx context.Context, account string, parameters interface{}) (string, error)
}
type RunnerError struct {
Code string
Message string
OrigErr error
}
// New constructs a RunnerError and returns it as an error
func NewRunnerError(code, message string, err error) RunnerError {
return RunnerError{
Code: code,
Message: message,
OrigErr: err,
}
}
// Error Satisfies the Error interface
func (e RunnerError) Error() string {
return e.String()
}
// String returns the error as string
func (e RunnerError) String() string {
if e.OrigErr != nil {
return fmt.Sprintf("%s: %s (%s)", e.Code, e.Message, e.OrigErr)
}
return fmt.Sprintf("%s: %s", e.Code, e.Message)
}
// Unwrap returns the contained error
func (e RunnerError) Unwrap() error {
return e.OrigErr
}