-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
49 lines (41 loc) · 928 Bytes
/
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
package wracha
import "fmt"
type (
baseError struct {
category string
message string
previousErr error
}
preActionError struct {
baseError
}
postActionError[T any] struct {
baseError
result ActionResult[T]
}
)
func newPreActionError(category string, message string, previousErr error) *preActionError {
return &preActionError{
baseError: baseError{
category: category,
message: message,
previousErr: previousErr,
},
}
}
func newPostActionError[T any](category string, message string, result ActionResult[T], previousErr error) *postActionError[T] {
return &postActionError[T]{
baseError: baseError{
category: category,
message: message,
previousErr: previousErr,
},
result: result,
}
}
func (e baseError) Error() string {
return fmt.Sprintf("%s (%s)", e.message, e.previousErr.Error())
}
func (a baseError) Unwrap() error {
return a.previousErr
}