-
Notifications
You must be signed in to change notification settings - Fork 225
/
Copy patherror_messages.rs
250 lines (233 loc) · 6.42 KB
/
error_messages.rs
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
//! Test error messages. As of 2023-03, this can hopefully be expanded significantly.
//! It's also fine to put errors by the things that they're testing.
//! See also [test_bad_error_messages.rs](test_bad_error_messages.rs) for error
//! messages which need to be improved.
use super::sql::compile;
use insta::assert_display_snapshot;
#[test]
fn test_errors() {
assert_display_snapshot!(compile(r###"
let addadd = a b -> a + b
from x
derive y = (addadd 4 5 6)
"###).unwrap_err(),
@r###"
Error:
╭─[:5:17]
│
5 │ derive y = (addadd 4 5 6)
│ ──────┬─────
│ ╰─────── Too many arguments to function `addadd`
───╯
"###);
assert_display_snapshot!(compile(r###"
from a select b
"###).unwrap_err(),
@r###"
Error:
╭─[:2:5]
│
2 │ from a select b
│ ───────┬───────
│ ╰───────── Too many arguments to function `from`
───╯
"###);
assert_display_snapshot!(compile(r###"
from x
select a
select b
"###).unwrap_err(),
@r###"
Error:
╭─[:4:12]
│
4 │ select b
│ ┬
│ ╰── Unknown name `b`
───╯
"###);
assert_display_snapshot!(compile(r###"
from employees
take 1.8
"###).unwrap_err(),
@r###"
Error:
╭─[:3:10]
│
3 │ take 1.8
│ ─┬─
│ ╰─── `take` expected int or range, but found 1.8
───╯
"###);
assert_display_snapshot!(compile("Mississippi has four S’s and four I’s.").unwrap_err(), @r###"
Error:
╭─[:1:23]
│
1 │ Mississippi has four S’s and four I’s.
│ ┬
│ ╰── unexpected ’
───╯
Error:
╭─[:1:36]
│
1 │ Mississippi has four S’s and four I’s.
│ ┬
│ ╰── unexpected ’
───╯
Error:
╭─[:1:38]
│
1 │ Mississippi has four S’s and four I’s.
│ ┬
│ ╰── Expected * or an identifier, but didn't find anything before the end.
───╯
"###);
assert_display_snapshot!(compile("Answer: T-H-A-T!").unwrap_err(), @r###"
Error:
╭─[:1:7]
│
1 │ Answer: T-H-A-T!
│ ┬
│ ╰── unexpected : while parsing function call
───╯
"###);
}
#[test]
fn test_union_all_sqlite() {
// TODO: `SQLiteDialect` would be better as `sql.sqlite` or `sqlite`.
assert_display_snapshot!(compile(r###"
prql target:sql.sqlite
from film
remove film2
"###).unwrap_err(), @r###"
Error: The dialect SQLiteDialect does not support EXCEPT ALL
↳ Hint: providing more column information will allow the query to be translated to an anti-join.
"###)
}
#[test]
fn test_regex_dialect() {
assert_display_snapshot!(compile(r###"
prql target:sql.mssql
from foo
filter bar ~= 'love'
"###).unwrap_err(), @r###"
Error:
╭─[:4:12]
│
4 │ filter bar ~= 'love'
│ ──────┬──────
│ ╰──────── operator std.regex_search is not supported for dialect mssql
───╯
"###)
}
#[test]
fn test_bad_function_type() {
assert_display_snapshot!(compile(r###"
from tracks
group foo (take)
"###,
)
.unwrap_err(), @r###"
Error:
╭─[:3:16]
│
3 │ group foo (take)
│ ──┬─
│ ╰─── function std.group, param `pipeline` expected type `transform`, but found type `func anytype relation -> relation`
│
│ Help: Type `transform` expands to `func relation -> relation`
───╯
"###);
}
#[test]
fn test_basic_type_checking() {
assert_display_snapshot!(compile(r#"
from foo
select (a && b) + c
"#)
.unwrap_err(), @r###"
Error:
╭─[:3:13]
│
3 │ select (a && b) + c
│ ───┬──
│ ╰──── function std.add, param `left` expected type `int || float || timestamp || date`, but found type `bool`
───╯
"###);
}
// See also test_bad_error_messages::misplaced_type_error
// Note that the ``` Help: Type `bool` expands to `bool` ``` is not that useful
#[test]
fn test_type_error_placement() {
assert_display_snapshot!(compile(r###"
let foo = x -> (x | as integer)
from t
select (true && (foo y))
"###).unwrap_err(), @r###"
Error:
╭─[:4:22]
│
4 │ select (true && (foo y))
│ ──┬──
│ ╰──── function std.and, param `right` expected type `bool`, but found type `scalar`
───╯
"###);
}
#[test]
fn test_ambiguous() {
assert_display_snapshot!(compile(r#"
from a
derive date = x
select date
"#)
.unwrap_err(), @r###"
Error:
╭─[:4:12]
│
4 │ select date
│ ──┬─
│ ╰─── Ambiguous name
│
│ Help: could be any of: std.date, this.date
───╯
"###);
}
#[test]
fn test_ambiguous_join() {
assert_display_snapshot!(compile(r#"
from a
select x
join (from b | select {x}) true
select x
"#)
.unwrap_err(), @r###"
Error:
╭─[:5:12]
│
5 │ select x
│ ┬
│ ╰── Ambiguous name
│
│ Help: could be any of: a.x, b.x
───╯
"###);
}
#[test]
fn test_ambiguous_inference() {
assert_display_snapshot!(compile(r#"
from a
join b (==b_id)
select x
"#)
.unwrap_err(), @r###"
Error:
╭─[:4:12]
│
4 │ select x
│ ┬
│ ╰── Ambiguous name
│
│ Help: could be any of: a.x, b.x
───╯
"###);
}