-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy patherrors.go
More file actions
111 lines (96 loc) · 1.95 KB
/
errors.go
File metadata and controls
111 lines (96 loc) · 1.95 KB
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
104
105
106
107
108
109
110
111
package sqlerr
import (
"errors"
"fmt"
)
var Exists = errors.New("already exists")
var NotFound = errors.New("does not exist")
var NotUnique = errors.New("is not unique")
type Error struct {
Err error
Code string
Message string
Location int
Line int
Column int
// Hint string
}
func (e *Error) Unwrap() error {
return e.Err
}
func (e *Error) Error() string {
if e.Err != nil {
return fmt.Sprintf("%s %s", e.Message, e.Err.Error())
} else {
return e.Message
}
}
func ColumnExists(rel, col string) *Error {
return &Error{
Err: Exists,
Code: "42701",
Message: fmt.Sprintf("column %q of relation %q", col, rel),
}
}
func ColumnNotFound(rel, col string) *Error {
return &Error{
Err: NotFound,
Code: "42703",
Message: fmt.Sprintf("column %q of relation %q", col, rel),
}
}
func RelationExists(rel string) *Error {
return &Error{
Err: Exists,
Code: "42P07",
Message: fmt.Sprintf("relation %q", rel),
}
}
func RelationNotFound(rel string) *Error {
return &Error{
Err: NotFound,
Code: "42P01",
Message: fmt.Sprintf("relation %q", rel),
}
}
func SchemaExists(name string) *Error {
return &Error{
Err: Exists,
Code: "42P06",
Message: fmt.Sprintf("schema %q", name),
}
}
func SchemaNotFound(sch string) *Error {
return &Error{
Err: NotFound,
Code: "3F000",
Message: fmt.Sprintf("schema %q", sch),
}
}
func TypeExists(typ string) *Error {
return &Error{
Err: Exists,
Code: "42710",
Message: fmt.Sprintf("type %q", typ),
}
}
func TypeNotFound(typ string) *Error {
return &Error{
Err: NotFound,
Code: "42704",
Message: fmt.Sprintf("type %q", typ),
}
}
func FunctionNotFound(fun string) *Error {
return &Error{
Err: NotFound,
Code: "42704",
Message: fmt.Sprintf("function %q", fun),
}
}
func FunctionNotUnique(fn string) *Error {
return &Error{
Err: NotUnique,
Message: fmt.Sprintf("function name %q", fn),
}
}