-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.go
103 lines (87 loc) · 1.99 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package quirk
import (
"fmt"
)
// Error is a general error that isn't super specific. Just used for when
// there needs to be more context relating to an error.
type Error struct {
ExtErr error
Msg string
File string
Function string
}
func (e *Error) Error() string {
if e.ExtErr != nil {
return fmt.Sprintf("%s:%s: msg[%s] external_err[%v]",
e.Function, e.File, e.Msg, e.ExtErr,
)
}
return fmt.Sprintf("%s:%s: msg[%s]",
e.Function, e.File, e.Msg,
)
}
// Unwrap is used to return any external errors.
// This function was implemented for Go 1.13.
func (e *Error) Unwrap() error {
if e.ExtErr != nil {
return e.ExtErr
}
return nil
}
// QueryError is used for functions in the query.go file.
type QueryError struct {
ExtErr error
Msg string
Function string
Query string
}
func (e *QueryError) Error() (res string) {
switch {
case e.ExtErr != nil:
res = fmt.Sprintf("%s:query.go: Query[%s] external_err[%v]",
e.Function, e.Query, e.ExtErr,
)
case e.Msg != "":
res = fmt.Sprintf("%s:query.go: Msg[%s]",
e.Function, e.Msg,
)
default:
res = fmt.Sprintf("%s:query.go: Query[%s]",
e.Function, e.Query,
)
}
return
}
// Unwrap is used to return any external errors.
// This function was implemented for Go 1.13.
func (e *QueryError) Unwrap() error {
if e.ExtErr != nil {
return e.ExtErr
}
return nil
}
// TransactionError is for when a transaction fails during a mutation.
type TransactionError struct {
ExtErr error
Msg string
Function string
RDF string
}
func (e *TransactionError) Error() string {
if e.ExtErr != nil {
return fmt.Sprintf("%s:mutate_single.go: Msg[%s] RDF[%s] external_err[%v]",
e.Function, e.Msg, e.RDF, e.ExtErr,
)
}
return fmt.Sprintf("%s:mutate_single.go: Msg[%s] RDF[%s]",
e.Function, e.Msg, e.RDF,
)
}
// Unwrap is used to return any external errors.
// This function was implemented for Go 1.13.
func (e *TransactionError) Unwrap() error {
if e.ExtErr != nil {
return e.ExtErr
}
return nil
}