-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
73 lines (64 loc) · 1.43 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
62
63
64
65
66
67
68
69
70
71
72
73
package tower
import (
"context"
"time"
)
type ErrorConstructorContext struct {
Err error
Caller Caller
Tower *Tower
}
type ErrorConstructor interface {
ConstructError(*ErrorConstructorContext) ErrorBuilder
}
type ErrorConstructorFunc func(*ErrorConstructorContext) ErrorBuilder
func (f ErrorConstructorFunc) ConstructError(ctx *ErrorConstructorContext) ErrorBuilder {
return f(ctx)
}
func defaultErrorGenerator(ctx *ErrorConstructorContext) ErrorBuilder {
var message string
if msg := Query.GetMessage(ctx.Err); msg != "" {
message = msg
} else {
message = ctx.Err.Error()
}
return &errorBuilder{
code: Query.GetCodeHint(ctx.Err),
message: message,
caller: ctx.Caller,
context: []any{},
level: ErrorLevel,
origin: ctx.Err,
tower: ctx.Tower,
time: time.Now(),
}
}
/*
Error is an interface providing read only values to the error, and because it's read only, this is safe for multithreaded use.
*/
type Error interface {
error
CallerHint
CodeHint
ContextHint
ErrorUnwrapper
ErrorWriter
HTTPCodeHint
KeyHint
LevelHint
MessageHint
TimeHint
ServiceHint
/*
Logs this error.
*/
Log(ctx context.Context) Error
/*
Notifies this error to Messengers.
*/
Notify(ctx context.Context, opts ...MessageOption) Error
}
type ErrorUnwrapper interface {
// Unwrap Returns the error that is wrapped by this error. To be used by errors.Is and errors.As functions from errors library.
Unwrap() error
}