-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy patherror.go
More file actions
41 lines (33 loc) · 706 Bytes
/
error.go
File metadata and controls
41 lines (33 loc) · 706 Bytes
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
package lambroll
import "errors"
type ExitCode int
const (
ExitCodeOK = ExitCode(0)
ExitCodeGeneralError = ExitCode(1)
ExitCodeDiffFound = ExitCode(2)
)
var ErrDiff = &ExitError{Code: ExitCodeDiffFound, Err: nil}
type ExitError struct {
Code ExitCode
Err error
}
func (e *ExitError) Error() string {
if e.Err == nil {
return ""
}
return e.Err.Error()
}
func (e *ExitError) Unwrap() error {
return nil
}
// ExtractExitCode extracts exit code from error.
func extractExitCodeAndError(err error) (int, error) {
if err == nil {
return int(ExitCodeOK), nil
}
var e *ExitError
if errors.As(err, &e) {
return int(e.Code), e.Err
}
return int(ExitCodeGeneralError), err
}