forked from compose/transporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
54 lines (48 loc) · 1.14 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
package adaptor
import (
"fmt"
)
// Adaptor errors have levels to indicate their severity.
// CRITICAL errors indicate that the program cannot continue running.
//
// ERROR errors indicate a problem with a specific document or message.
// a document might not have been applied properly to a source, but the program can continue
//
// WARNING Todo
//
// NOTICE ToDo
const (
NOTICE ErrorLevel = iota
WARNING
ERROR
CRITICAL
)
// ErrorLevel indicated the severity of the error
type ErrorLevel int
func levelToString(lvl ErrorLevel) string {
switch lvl {
case NOTICE:
return "NOTICE"
case WARNING:
return "WARNING"
case ERROR:
return "ERROR"
case CRITICAL:
return "CRITICAL"
default:
return "UNKNOWN"
}
}
// Error is an error that happened during an adaptor's operation.
// Error's include both an indication of the severity, Level, as well as
// a reference to the Record that was in process when the error occurred
type Error struct {
Lvl ErrorLevel
Err string
Path string
Record interface{}
}
// Error returns the error as a string
func (t Error) Error() string {
return fmt.Sprintf("%s: %s", levelToString(t.Lvl), t.Err)
}