-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
136 lines (125 loc) · 3.14 KB
/
errors.go
File metadata and controls
136 lines (125 loc) · 3.14 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package cql2
import (
"fmt"
"strings"
)
// SyntaxError is returned when input cannot be parsed.
type SyntaxError struct {
Encoding Encoding
At Pos
Snippet string
Msg string
Got string
Expected []string
}
func (e *SyntaxError) Error() string {
var b strings.Builder
switch e.Encoding {
case EncodingJSON:
b.WriteString("json")
default:
b.WriteString("text")
}
if e.At != (Pos{}) {
fmt.Fprintf(&b, ":%s", e.At.String())
}
b.WriteString(": ")
if e.Msg != "" {
b.WriteString(e.Msg)
} else {
b.WriteString("syntax error")
}
if e.Got != "" {
fmt.Fprintf(&b, " (got %q", e.Got)
if len(e.Expected) > 0 {
fmt.Fprintf(&b, ", expected one of: %s", strings.Join(e.Expected, ", "))
}
b.WriteByte(')')
} else if len(e.Expected) > 0 {
fmt.Fprintf(&b, " (expected one of: %s)", strings.Join(e.Expected, ", "))
}
if e.Snippet != "" {
fmt.Fprintf(&b, " near %q", e.Snippet)
}
return b.String()
}
// ConformanceError is returned when input requires a conformance class
// that is not enabled in the active configuration.
type ConformanceError struct {
Required Conformance
Active Conformance
Feature string
At Pos
}
func (e *ConformanceError) Error() string {
var b strings.Builder
b.WriteString("conformance error")
if e.At != (Pos{}) {
fmt.Fprintf(&b, " at %s", e.At.String())
}
if e.Feature != "" {
fmt.Fprintf(&b, ": feature %q", e.Feature)
}
fmt.Fprintf(&b, ": required=0x%x active=0x%x", uint32(e.Required), uint32(e.Active))
return b.String()
}
// GeometryError is returned for malformed WKT or GeoJSON geometry.
type GeometryError struct {
Encoding Encoding
At Pos
Msg string
}
func (e *GeometryError) Error() string {
var b strings.Builder
switch e.Encoding {
case EncodingJSON:
b.WriteString("geojson")
default:
b.WriteString("wkt")
}
if e.At != (Pos{}) {
fmt.Fprintf(&b, ":%s", e.At.String())
}
b.WriteString(": ")
if e.Msg != "" {
b.WriteString(e.Msg)
} else {
b.WriteString("invalid geometry")
}
return b.String()
}
// UnliftableError is returned when a Go value cannot be lifted to a Node.
type UnliftableError struct {
Value any
Msg string
}
func (e *UnliftableError) Error() string {
if e.Msg != "" {
return fmt.Sprintf("cannot lift %T: %s", e.Value, e.Msg)
}
return fmt.Sprintf("cannot lift %T", e.Value)
}
// ValidationError is returned by Validate when an AST is structurally
// well-formed (parsed without error) but violates spec arity or shape
// constraints — for example a comparison op with three args, or IN
// whose RHS is not an ArrayLit.
type ValidationError struct {
// Op is set when the violation is on an *Op node; empty otherwise.
Op Operator
// Function is set when the violation is on a *FunctionCall node.
Function string
// Msg is a human-readable description of the violation.
Msg string
// Node is the offending AST node.
Node Node
}
func (e *ValidationError) Error() string {
switch {
case e.Op != "":
return fmt.Sprintf("validation: operator %q: %s", string(e.Op), e.Msg)
case e.Function != "":
return fmt.Sprintf("validation: function %q: %s", e.Function, e.Msg)
default:
return fmt.Sprintf("validation: %s", e.Msg)
}
}