Skip to content

Commit 276ce26

Browse files
committed
internal/core/adt: record more error positions
Method: replace `ctx.Str(x)` arguments to formatting with `x` and let the error methods do the conversion. This gives access to position information as well, which can then be added to the errors. This has the additional benefit that this will allow lazy expansion of error printing down the road. Note that in some cases we now drop the "main" position as it would result in too much redundancy. In tests this manifests itself as a slight change of the column position. Fixes #905 Closes #129 Issue #52 Change-Id: I044cf34b9718f05553139974c6c166d2630568e6 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9446 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent c5c9125 commit 276ce26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+241
-96
lines changed

cue/testdata/basicrewrite/001_regexp.txtar

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ b3: invalid value "foo" (out of bound =~"[a-z]{4}"):
7474
./in.cue:11:5
7575
e1: cannot use 1 (type int) as type (string|bytes):
7676
./in.cue:20:5
77+
./in.cue:20:14
7778
e2: cannot use true (type bool) as type (string|bytes):
7879
./in.cue:21:5
80+
./in.cue:21:14
7981

8082
Result:
8183
(_|_){
@@ -99,10 +101,12 @@ Result:
99101
e1: (_|_){
100102
// [eval] e1: cannot use 1 (type int) as type (string|bytes):
101103
// ./in.cue:20:5
104+
// ./in.cue:20:14
102105
}
103106
e2: (_|_){
104107
// [eval] e2: cannot use true (type bool) as type (string|bytes):
105108
// ./in.cue:21:5
109+
// ./in.cue:21:14
106110
}
107111
e3: (_|_){
108112
// [eval] e3: conflicting values !="a" and <5 (mismatched types string and number):

cue/testdata/basicrewrite/002_arithmetic.txtar

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,19 @@ irem00: division by zero:
109109
./in.cue:16:9
110110
e0: invalid operands 2 and "a" to '+' (type int and string):
111111
./in.cue:23:5
112+
./in.cue:23:9
112113
e5: invalid operands 1.0 and 2 to 'div' (type float and int):
113114
./in.cue:29:5
115+
./in.cue:29:13
114116
e6: invalid operands 2 and 2.0 to 'rem' (type int and float):
115117
./in.cue:30:5
118+
./in.cue:30:11
116119
e7: invalid operands 2 and 2.0 to 'quo' (type int and float):
117120
./in.cue:31:5
121+
./in.cue:31:11
118122
e8: invalid operands 1.0 and 1 to 'mod' (type float and int):
119123
./in.cue:32:5
124+
./in.cue:32:13
120125

121126
Result:
122127
(_|_){
@@ -160,21 +165,26 @@ Result:
160165
e0: (_|_){
161166
// [eval] e0: invalid operands 2 and "a" to '+' (type int and string):
162167
// ./in.cue:23:5
168+
// ./in.cue:23:9
163169
}
164170
e5: (_|_){
165171
// [eval] e5: invalid operands 1.0 and 2 to 'div' (type float and int):
166172
// ./in.cue:29:5
173+
// ./in.cue:29:13
167174
}
168175
e6: (_|_){
169176
// [eval] e6: invalid operands 2 and 2.0 to 'rem' (type int and float):
170177
// ./in.cue:30:5
178+
// ./in.cue:30:11
171179
}
172180
e7: (_|_){
173181
// [eval] e7: invalid operands 2 and 2.0 to 'quo' (type int and float):
174182
// ./in.cue:31:5
183+
// ./in.cue:31:11
175184
}
176185
e8: (_|_){
177186
// [eval] e8: invalid operands 1.0 and 1 to 'mod' (type float and int):
178187
// ./in.cue:32:5
188+
// ./in.cue:32:13
179189
}
180190
}

cue/testdata/basicrewrite/003_integer-specific_arithmetic.txtar

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,28 @@ me2: _|_ // invalid operation 2 mod 1.0 (mismatched types int and float)
8989
Errors:
9090
qe1: invalid operands 2.0 and 1 to 'quo' (type float and int):
9191
./in.cue:5:6
92+
./in.cue:5:14
9293
qe2: invalid operands 2 and 1.0 to 'quo' (type int and float):
9394
./in.cue:6:6
95+
./in.cue:6:12
9496
re1: invalid operands 2.0 and 1 to 'rem' (type float and int):
9597
./in.cue:12:6
98+
./in.cue:12:14
9699
re2: invalid operands 2 and 1.0 to 'rem' (type int and float):
97100
./in.cue:13:6
101+
./in.cue:13:12
98102
de1: invalid operands 2.0 and 1 to 'div' (type float and int):
99103
./in.cue:19:6
104+
./in.cue:19:14
100105
de2: invalid operands 2 and 1.0 to 'div' (type int and float):
101106
./in.cue:20:6
107+
./in.cue:20:12
102108
me1: invalid operands 2.0 and 1 to 'mod' (type float and int):
103109
./in.cue:26:6
110+
./in.cue:26:14
104111
me2: invalid operands 2 and 1.0 to 'mod' (type int and float):
105112
./in.cue:27:6
113+
./in.cue:27:12
106114

107115
Result:
108116
(_|_){
@@ -114,10 +122,12 @@ Result:
114122
qe1: (_|_){
115123
// [eval] qe1: invalid operands 2.0 and 1 to 'quo' (type float and int):
116124
// ./in.cue:5:6
125+
// ./in.cue:5:14
117126
}
118127
qe2: (_|_){
119128
// [eval] qe2: invalid operands 2 and 1.0 to 'quo' (type int and float):
120129
// ./in.cue:6:6
130+
// ./in.cue:6:12
121131
}
122132
r1: (int){ 1 }
123133
r2: (int){ 1 }
@@ -126,10 +136,12 @@ Result:
126136
re1: (_|_){
127137
// [eval] re1: invalid operands 2.0 and 1 to 'rem' (type float and int):
128138
// ./in.cue:12:6
139+
// ./in.cue:12:14
129140
}
130141
re2: (_|_){
131142
// [eval] re2: invalid operands 2 and 1.0 to 'rem' (type int and float):
132143
// ./in.cue:13:6
144+
// ./in.cue:13:12
133145
}
134146
d1: (int){ 2 }
135147
d2: (int){ -2 }
@@ -138,10 +150,12 @@ Result:
138150
de1: (_|_){
139151
// [eval] de1: invalid operands 2.0 and 1 to 'div' (type float and int):
140152
// ./in.cue:19:6
153+
// ./in.cue:19:14
141154
}
142155
de2: (_|_){
143156
// [eval] de2: invalid operands 2 and 1.0 to 'div' (type int and float):
144157
// ./in.cue:20:6
158+
// ./in.cue:20:12
145159
}
146160
m1: (int){ 1 }
147161
m2: (int){ 1 }
@@ -150,9 +164,11 @@ Result:
150164
me1: (_|_){
151165
// [eval] me1: invalid operands 2.0 and 1 to 'mod' (type float and int):
152166
// ./in.cue:26:6
167+
// ./in.cue:26:14
153168
}
154169
me2: (_|_){
155170
// [eval] me2: invalid operands 2 and 1.0 to 'mod' (type int and float):
156171
// ./in.cue:27:6
172+
// ./in.cue:27:12
157173
}
158174
}

cue/testdata/basicrewrite/007_strings_and_bytes.txtar

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ e1: _|_ // invalid operation 'b' + "c" (mismatched types bytes and string)
4343
Errors:
4444
e0: invalid operands "a" and '' to '+' (type string and bytes):
4545
./in.cue:10:5
46+
./in.cue:10:11
4647
e1: invalid operands 'b' and "c" to '+' (type bytes and string):
4748
./in.cue:11:5
49+
./in.cue:11:11
4850

4951
Result:
5052
(_|_){
@@ -58,9 +60,11 @@ Result:
5860
e0: (_|_){
5961
// [eval] e0: invalid operands "a" and '' to '+' (type string and bytes):
6062
// ./in.cue:10:5
63+
// ./in.cue:10:11
6164
}
6265
e1: (_|_){
6366
// [eval] e1: invalid operands 'b' and "c" to '+' (type bytes and string):
6467
// ./in.cue:11:5
68+
// ./in.cue:11:11
6569
}
6670
}

cue/testdata/basicrewrite/010_lists.txtar

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ e2: invalid list index d (type string):
8383
./in.cue:5:12
8484
e3: invalid index -1 (index must be non-negative):
8585
./in.cue:6:8
86+
./in.cue:6:12
8687
e4.3: invalid value 8 (out of bound <=5):
8788
./in.cue:7:24
8889
./in.cue:7:41
@@ -116,6 +117,7 @@ Result:
116117
e3: (_|_){
117118
// [eval] e3: invalid index -1 (index must be non-negative):
118119
// ./in.cue:6:8
120+
// ./in.cue:6:12
119121
}
120122
e4: (_|_){
121123
// [eval]

cue/testdata/basicrewrite/015_types.txtar

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ m: _|_ // invalid operation -false (- bool)
3939
}
4040
-- out/eval --
4141
Errors:
42+
b: invalid operand int ('!' requires concrete value):
43+
./in.cue:7:6
4244
e: conflicting values int and string (mismatched types int and string):
4345
./in.cue:5:5
4446
./in.cue:5:11
4547
e2: conflicting values 1 and string (mismatched types int and string):
4648
./in.cue:6:5
4749
./in.cue:6:9
48-
b: invalid operand int ('!' requires concrete value):
49-
./in.cue:7:5
5050
p: invalid operation +true (+ bool):
5151
./in.cue:8:5
5252
m: invalid operation -false (- bool):
@@ -71,7 +71,7 @@ Result:
7171
}
7272
b: (_|_){
7373
// [eval] b: invalid operand int ('!' requires concrete value):
74-
// ./in.cue:7:5
74+
// ./in.cue:7:6
7575
}
7676
p: (_|_){
7777
// [eval] p: invalid operation +true (+ bool):

cue/testdata/basicrewrite/016_comparison.txtar

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ err: _|_ // invalid operation 2 == "s" (mismatched types int and string)
4040
Errors:
4141
err: invalid operands 2 and "s" to '==' (type int and string):
4242
./in.cue:9:6
43+
./in.cue:9:11
4344

4445
Result:
4546
(_|_){
@@ -54,5 +55,6 @@ Result:
5455
err: (_|_){
5556
// [eval] err: invalid operands 2 and "s" to '==' (type int and string):
5657
// ./in.cue:9:6
58+
// ./in.cue:9:11
5759
}
5860
}

cue/testdata/builtins/all.txtar

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ okIncompleteChild: {
2222
Errors:
2323
fatalArg.x: invalid operands "eee" and 'eee' to '+' (type string and bytes):
2424
./in.cue:3:12
25+
./in.cue:3:20
2526
0.a: undefined field c:
2627
./in.cue:9:20
2728

@@ -33,6 +34,7 @@ Result:
3334
x: (_|_){
3435
// [eval] fatalArg.x: invalid operands "eee" and 'eee' to '+' (type string and bytes):
3536
// ./in.cue:3:12
37+
// ./in.cue:3:20
3638
}
3739
}
3840
fatalChild: (_|_){

cue/testdata/builtins/incomplete.txtar

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join:
9595
./in.cue:77:8
9696
badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
9797
./in.cue:83:8
98+
./in.cue:84:8
9899

99100
Result:
100101
(_|_){
@@ -194,10 +195,12 @@ Result:
194195
transformed: (_|_){
195196
// [incomplete] incompleteArgStringList.#a.transformed: non-concrete value string in operand to +:
196197
// ./in.cue:58:22
198+
// ./in.cue:57:9
197199
}
198200
joined: (_|_){
199201
// [incomplete] 0: non-concrete value string in operand to +:
200202
// ./in.cue:58:22
203+
// ./in.cue:57:9
201204
}
202205
}
203206
}
@@ -216,15 +219,18 @@ Result:
216219
x: (_|_){
217220
// [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
218221
// ./in.cue:70:8
222+
// ./in.cue:71:5
219223
}
220224
y: (_){ _ }
221225
decimal: (_|_){
222226
// [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
223227
// ./in.cue:70:8
228+
// ./in.cue:71:5
224229
}
225230
str: (_|_){
226231
// [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
227232
// ./in.cue:70:8
233+
// ./in.cue:71:5
228234
}
229235
}
230236
badListType: (_|_){
@@ -244,15 +250,18 @@ Result:
244250
x: (_|_){
245251
// [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
246252
// ./in.cue:83:8
253+
// ./in.cue:84:8
247254
}
248255
y: (string){ "foo" }
249256
decimal: (_|_){
250257
// [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
251258
// ./in.cue:83:8
259+
// ./in.cue:84:8
252260
}
253261
str: (_|_){
254262
// [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
255263
// ./in.cue:83:8
264+
// ./in.cue:84:8
256265
}
257266
}
258267
}

cue/testdata/builtins/issue299.txtar

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ x: [string, ...string]
55
x: ["x","x"]
66
-- out/eval --
77
Errors:
8-
x: invalid value ["x","x"] (does not satisfy list.UniqueItems)
8+
x: invalid value ["x","x"] (does not satisfy list.UniqueItems):
9+
./in.cue:2:1
10+
./in.cue:3:1
11+
./in.cue:4:1
912

1013
Result:
1114
(_|_){
1215
// [eval]
1316
x: (_|_){
14-
// [eval] x: invalid value ["x","x"] (does not satisfy list.UniqueItems)
17+
// [eval] x: invalid value ["x","x"] (does not satisfy list.UniqueItems):
18+
// ./in.cue:2:1
19+
// ./in.cue:3:1
20+
// ./in.cue:4:1
1521
0: (string){ "x" }
1622
1: (string){ "x" }
1723
}

0 commit comments

Comments
 (0)