/
error.go
61 lines (58 loc) · 1.16 KB
/
error.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
61
package errs
import (
"context"
"errors"
cu "github.com/nj-eka/shurl/internal/contexts"
"time"
)
type Error interface {
error
Severity() Severity
TimeStamp() time.Time
Kind() Kind
RequestID() string
OperationPath() cu.Operations
StackTrace() []Frame
Unwrap() error
}
func E(args ...interface{}) Error {
switch len(args) {
case 0:
panic("call to errors.E with no arguments")
case 1:
if e, ok := args[0].(Error); ok {
return e
}
}
e := newError().(errorData)
// the last on the list [args] wins
for _, arg := range args {
switch a := arg.(type) {
case Severity:
e.severity = a
case Kind:
e.kind = a
case cu.Operation:
e.ops = cu.Operations{Stack: []cu.Operation{a}}
case cu.Operations:
e.ops = a
case context.Context:
e.ops = cu.GetContextOperations(a)
e.kind = GetDefaultErrsKind(a)
e.severity = GetDefaultErrsSeverity(a)
e.requestId = cu.GetRequestID(a)
case Error: // todo: impl transient error in this case (need more cases...)
e.err = a
if e.kind == KindOther {
e.kind = KindTransient
}
case error:
e.err = a
case string:
e.err = errors.New(a)
default:
}
}
e.frames = Trace(2)
return e
}