-
Notifications
You must be signed in to change notification settings - Fork 225
/
Copy pathtest_bad_error_messages.rs
165 lines (154 loc) · 5.06 KB
/
test_bad_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
//! Record bad error messages here which we should improve.
//!
//! Some of these will be good issues for new contributors, or for more
//! experienced contributors who would like a quick issue to fix:
//! - Find where the error is being raised now, generally just search for a part
//! of the message.
//! - Add `dbg` macros to the code to see what's going on.
//! - Write a better message / find a better place to raise a message.
//! - Run `cargo insta test --accept`, and move the test out of this file into
//! `test_error_messages.rs`. If it's only partially solved, add a TODO and
//! make a call for where it should go.
//!
//! Adding bad error messages here is also a welcome contribution. Probably
//! one-issue-per-error-message is not a good way of managing them — there would
//! be a huge number of issues, and it would be difficult to see what's current.
//! So instead, add the error message as a test here.
use super::compile;
use insta::assert_display_snapshot;
#[test]
fn test_bad_error_messages() {
assert_display_snapshot!(compile(r###"
from film
group
"###).unwrap_err(), @r###"
Error:
╭─[:3:5]
│
3 │ group
│ ──┬──
│ ╰──── main expected type `relation`, but found type `transform relation -> relation`
│
│ Help: Have you forgotten an argument to function std.group?
│
│ Note: Type `relation` expands to `[tuple_of_scalars]`
───╯
"###);
// This should suggest parentheses (this might not be an easy one to solve)
assert_display_snapshot!(compile(r#"
let f = country -> country == "Canada"
from employees
filter f location
"#).unwrap_err(), @r###"
Error:
╭─[:5:14]
│
5 │ filter f location
│ ────┬───
│ ╰───── Unknown name `location`
───╯
"###);
// Really complicated error message for something so fundamental
assert_display_snapshot!(compile(r###"
select tracks
from artists
"###).unwrap_err(), @r###"
Error:
╭─[:3:5]
│
3 │ from artists
│ ──────┬─────
│ ╰─────── expected a function, but found `default_db.artists`
───╯
"###);
// It's better if we can tell them to put in {} braces
assert_display_snapshot!(compile(r###"
from artists
sort -name
"###).unwrap_err(), @r###"
Error: expected a pipeline that resolves to a table, but found `internal std.sub`
↳ Hint: are you missing `from` statement?
"###);
}
#[test]
fn array_instead_of_tuple() {
// Particularly given this used to be our syntax, this could be clearer
// (though we do say so in the message, which is friendly!)
assert_display_snapshot!(compile(r###"
from e=employees
select [e.first_name, e.last_name]
"###).unwrap_err(), @r###"
Error:
╭─[:3:12]
│
3 │ select [e.first_name, e.last_name]
│ ─────────────┬─────────────
│ ╰─────────────── unexpected `[this.e.first_name, this.e.last_name]`
│
│ Help: this is probably a 'bad type' error (we are working on that)
───╯
"###);
}
#[test]
fn empty_interpolations() {
assert_display_snapshot!(compile(r#"
from x
select f"{}"
"#).unwrap_err(), @r###"
Error:
╭─[:3:14]
│
3 │ select f"{}"
│ ┬
│ ╰── unexpected end of input while parsing interpolated string
───╯
"###);
}
#[test]
fn select_with_extra_fstr() {
// Should complain in the same way as `select lower "mooo"`
assert_display_snapshot!(compile(r#"
from foo
select lower f"{x}/{y}"
"#).unwrap_err(), @r###"
Error:
╭─[:3:20]
│
3 │ select lower f"{x}/{y}"
│ ─┬─
│ ╰─── Unknown name `x`
───╯
"###);
}
// See also test_error_messages::test_type_error_placement
#[test]
fn misplaced_type_error() {
// This one should point at `foo` in `select (... foo)`
// (preferably in addition to the error that is currently generated)
assert_display_snapshot!(compile(r###"
let foo = 123
from t
select (true && foo)
"###).unwrap_err(), @r###"
Error:
╭─[:2:15]
│
2 │ let foo = 123
│ ─┬─
│ ╰─── function std.and, param `right` expected type `bool`, but found type `int`
│
│ Help: Type `bool` expands to `bool`
───╯
"###);
}
#[test]
fn invalid_lineage_in_transform() {
assert_display_snapshot!(compile(r###"
from tbl
group id (
sort -val
)
"###).unwrap_err(), @r###"
Error: "Invalid lineage in group, verify the contents of the group call"
"###);
}