Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal/core/adt: record more error positions
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mpvl committed Apr 20, 2021
1 parent c5c9125 commit 276ce26
Show file tree
Hide file tree
Showing 45 changed files with 241 additions and 96 deletions.
4 changes: 4 additions & 0 deletions cue/testdata/basicrewrite/001_regexp.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ b3: invalid value "foo" (out of bound =~"[a-z]{4}"):
./in.cue:11:5
e1: cannot use 1 (type int) as type (string|bytes):
./in.cue:20:5
./in.cue:20:14
e2: cannot use true (type bool) as type (string|bytes):
./in.cue:21:5
./in.cue:21:14

Result:
(_|_){
Expand All @@ -99,10 +101,12 @@ Result:
e1: (_|_){
// [eval] e1: cannot use 1 (type int) as type (string|bytes):
// ./in.cue:20:5
// ./in.cue:20:14
}
e2: (_|_){
// [eval] e2: cannot use true (type bool) as type (string|bytes):
// ./in.cue:21:5
// ./in.cue:21:14
}
e3: (_|_){
// [eval] e3: conflicting values !="a" and <5 (mismatched types string and number):
Expand Down
10 changes: 10 additions & 0 deletions cue/testdata/basicrewrite/002_arithmetic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,19 @@ irem00: division by zero:
./in.cue:16:9
e0: invalid operands 2 and "a" to '+' (type int and string):
./in.cue:23:5
./in.cue:23:9
e5: invalid operands 1.0 and 2 to 'div' (type float and int):
./in.cue:29:5
./in.cue:29:13
e6: invalid operands 2 and 2.0 to 'rem' (type int and float):
./in.cue:30:5
./in.cue:30:11
e7: invalid operands 2 and 2.0 to 'quo' (type int and float):
./in.cue:31:5
./in.cue:31:11
e8: invalid operands 1.0 and 1 to 'mod' (type float and int):
./in.cue:32:5
./in.cue:32:13

Result:
(_|_){
Expand Down Expand Up @@ -160,21 +165,26 @@ Result:
e0: (_|_){
// [eval] e0: invalid operands 2 and "a" to '+' (type int and string):
// ./in.cue:23:5
// ./in.cue:23:9
}
e5: (_|_){
// [eval] e5: invalid operands 1.0 and 2 to 'div' (type float and int):
// ./in.cue:29:5
// ./in.cue:29:13
}
e6: (_|_){
// [eval] e6: invalid operands 2 and 2.0 to 'rem' (type int and float):
// ./in.cue:30:5
// ./in.cue:30:11
}
e7: (_|_){
// [eval] e7: invalid operands 2 and 2.0 to 'quo' (type int and float):
// ./in.cue:31:5
// ./in.cue:31:11
}
e8: (_|_){
// [eval] e8: invalid operands 1.0 and 1 to 'mod' (type float and int):
// ./in.cue:32:5
// ./in.cue:32:13
}
}
16 changes: 16 additions & 0 deletions cue/testdata/basicrewrite/003_integer-specific_arithmetic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,28 @@ me2: _|_ // invalid operation 2 mod 1.0 (mismatched types int and float)
Errors:
qe1: invalid operands 2.0 and 1 to 'quo' (type float and int):
./in.cue:5:6
./in.cue:5:14
qe2: invalid operands 2 and 1.0 to 'quo' (type int and float):
./in.cue:6:6
./in.cue:6:12
re1: invalid operands 2.0 and 1 to 'rem' (type float and int):
./in.cue:12:6
./in.cue:12:14
re2: invalid operands 2 and 1.0 to 'rem' (type int and float):
./in.cue:13:6
./in.cue:13:12
de1: invalid operands 2.0 and 1 to 'div' (type float and int):
./in.cue:19:6
./in.cue:19:14
de2: invalid operands 2 and 1.0 to 'div' (type int and float):
./in.cue:20:6
./in.cue:20:12
me1: invalid operands 2.0 and 1 to 'mod' (type float and int):
./in.cue:26:6
./in.cue:26:14
me2: invalid operands 2 and 1.0 to 'mod' (type int and float):
./in.cue:27:6
./in.cue:27:12

Result:
(_|_){
Expand All @@ -114,10 +122,12 @@ Result:
qe1: (_|_){
// [eval] qe1: invalid operands 2.0 and 1 to 'quo' (type float and int):
// ./in.cue:5:6
// ./in.cue:5:14
}
qe2: (_|_){
// [eval] qe2: invalid operands 2 and 1.0 to 'quo' (type int and float):
// ./in.cue:6:6
// ./in.cue:6:12
}
r1: (int){ 1 }
r2: (int){ 1 }
Expand All @@ -126,10 +136,12 @@ Result:
re1: (_|_){
// [eval] re1: invalid operands 2.0 and 1 to 'rem' (type float and int):
// ./in.cue:12:6
// ./in.cue:12:14
}
re2: (_|_){
// [eval] re2: invalid operands 2 and 1.0 to 'rem' (type int and float):
// ./in.cue:13:6
// ./in.cue:13:12
}
d1: (int){ 2 }
d2: (int){ -2 }
Expand All @@ -138,10 +150,12 @@ Result:
de1: (_|_){
// [eval] de1: invalid operands 2.0 and 1 to 'div' (type float and int):
// ./in.cue:19:6
// ./in.cue:19:14
}
de2: (_|_){
// [eval] de2: invalid operands 2 and 1.0 to 'div' (type int and float):
// ./in.cue:20:6
// ./in.cue:20:12
}
m1: (int){ 1 }
m2: (int){ 1 }
Expand All @@ -150,9 +164,11 @@ Result:
me1: (_|_){
// [eval] me1: invalid operands 2.0 and 1 to 'mod' (type float and int):
// ./in.cue:26:6
// ./in.cue:26:14
}
me2: (_|_){
// [eval] me2: invalid operands 2 and 1.0 to 'mod' (type int and float):
// ./in.cue:27:6
// ./in.cue:27:12
}
}
4 changes: 4 additions & 0 deletions cue/testdata/basicrewrite/007_strings_and_bytes.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ e1: _|_ // invalid operation 'b' + "c" (mismatched types bytes and string)
Errors:
e0: invalid operands "a" and '' to '+' (type string and bytes):
./in.cue:10:5
./in.cue:10:11
e1: invalid operands 'b' and "c" to '+' (type bytes and string):
./in.cue:11:5
./in.cue:11:11

Result:
(_|_){
Expand All @@ -58,9 +60,11 @@ Result:
e0: (_|_){
// [eval] e0: invalid operands "a" and '' to '+' (type string and bytes):
// ./in.cue:10:5
// ./in.cue:10:11
}
e1: (_|_){
// [eval] e1: invalid operands 'b' and "c" to '+' (type bytes and string):
// ./in.cue:11:5
// ./in.cue:11:11
}
}
2 changes: 2 additions & 0 deletions cue/testdata/basicrewrite/010_lists.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ e2: invalid list index d (type string):
./in.cue:5:12
e3: invalid index -1 (index must be non-negative):
./in.cue:6:8
./in.cue:6:12
e4.3: invalid value 8 (out of bound <=5):
./in.cue:7:24
./in.cue:7:41
Expand Down Expand Up @@ -116,6 +117,7 @@ Result:
e3: (_|_){
// [eval] e3: invalid index -1 (index must be non-negative):
// ./in.cue:6:8
// ./in.cue:6:12
}
e4: (_|_){
// [eval]
Expand Down
6 changes: 3 additions & 3 deletions cue/testdata/basicrewrite/015_types.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ m: _|_ // invalid operation -false (- bool)
}
-- out/eval --
Errors:
b: invalid operand int ('!' requires concrete value):
./in.cue:7:6
e: conflicting values int and string (mismatched types int and string):
./in.cue:5:5
./in.cue:5:11
e2: conflicting values 1 and string (mismatched types int and string):
./in.cue:6:5
./in.cue:6:9
b: invalid operand int ('!' requires concrete value):
./in.cue:7:5
p: invalid operation +true (+ bool):
./in.cue:8:5
m: invalid operation -false (- bool):
Expand All @@ -71,7 +71,7 @@ Result:
}
b: (_|_){
// [eval] b: invalid operand int ('!' requires concrete value):
// ./in.cue:7:5
// ./in.cue:7:6
}
p: (_|_){
// [eval] p: invalid operation +true (+ bool):
Expand Down
2 changes: 2 additions & 0 deletions cue/testdata/basicrewrite/016_comparison.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ err: _|_ // invalid operation 2 == "s" (mismatched types int and string)
Errors:
err: invalid operands 2 and "s" to '==' (type int and string):
./in.cue:9:6
./in.cue:9:11

Result:
(_|_){
Expand All @@ -54,5 +55,6 @@ Result:
err: (_|_){
// [eval] err: invalid operands 2 and "s" to '==' (type int and string):
// ./in.cue:9:6
// ./in.cue:9:11
}
}
2 changes: 2 additions & 0 deletions cue/testdata/builtins/all.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ okIncompleteChild: {
Errors:
fatalArg.x: invalid operands "eee" and 'eee' to '+' (type string and bytes):
./in.cue:3:12
./in.cue:3:20
0.a: undefined field c:
./in.cue:9:20

Expand All @@ -33,6 +34,7 @@ Result:
x: (_|_){
// [eval] fatalArg.x: invalid operands "eee" and 'eee' to '+' (type string and bytes):
// ./in.cue:3:12
// ./in.cue:3:20
}
}
fatalChild: (_|_){
Expand Down
9 changes: 9 additions & 0 deletions cue/testdata/builtins/incomplete.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join:
./in.cue:77:8
badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
./in.cue:83:8
./in.cue:84:8

Result:
(_|_){
Expand Down Expand Up @@ -194,10 +195,12 @@ Result:
transformed: (_|_){
// [incomplete] incompleteArgStringList.#a.transformed: non-concrete value string in operand to +:
// ./in.cue:58:22
// ./in.cue:57:9
}
joined: (_|_){
// [incomplete] 0: non-concrete value string in operand to +:
// ./in.cue:58:22
// ./in.cue:57:9
}
}
}
Expand All @@ -216,15 +219,18 @@ Result:
x: (_|_){
// [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
// ./in.cue:70:8
// ./in.cue:71:5
}
y: (_){ _ }
decimal: (_|_){
// [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
// ./in.cue:70:8
// ./in.cue:71:5
}
str: (_|_){
// [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
// ./in.cue:70:8
// ./in.cue:71:5
}
}
badListType: (_|_){
Expand All @@ -244,15 +250,18 @@ Result:
x: (_|_){
// [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
// ./in.cue:83:8
// ./in.cue:84:8
}
y: (string){ "foo" }
decimal: (_|_){
// [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
// ./in.cue:83:8
// ./in.cue:84:8
}
str: (_|_){
// [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
// ./in.cue:83:8
// ./in.cue:84:8
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions cue/testdata/builtins/issue299.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ x: [string, ...string]
x: ["x","x"]
-- out/eval --
Errors:
x: invalid value ["x","x"] (does not satisfy list.UniqueItems)
x: invalid value ["x","x"] (does not satisfy list.UniqueItems):
./in.cue:2:1
./in.cue:3:1
./in.cue:4:1

Result:
(_|_){
// [eval]
x: (_|_){
// [eval] x: invalid value ["x","x"] (does not satisfy list.UniqueItems)
// [eval] x: invalid value ["x","x"] (does not satisfy list.UniqueItems):
// ./in.cue:2:1
// ./in.cue:3:1
// ./in.cue:4:1
0: (string){ "x" }
1: (string){ "x" }
}
Expand Down
4 changes: 4 additions & 0 deletions cue/testdata/builtins/validators.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ Result:
kv: (_|_){
// [incomplete] incompleteError2.MyType.kv: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
// ./in.cue:22:17
// ./in.cue:21:13
// ./in.cue:22:13
// ./in.cue:22:34
}
}
Expand All @@ -148,6 +150,8 @@ Result:
kv: (_|_){
// [incomplete] violation.#MyType.kv: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
// ./in.cue:49:17
// ./in.cue:48:13
// ./in.cue:49:13
// ./in.cue:49:34
}
}
Expand Down
1 change: 1 addition & 0 deletions cue/testdata/comprehensions/errors.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Result:
userError: (_|_){
// [incomplete] userError: non-concrete value string in operand to !=:
// ./in.cue:21:8
// ./in.cue:20:5
a: (string){ string }
}
}
Expand Down
2 changes: 2 additions & 0 deletions cue/testdata/comprehensions/iferror.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ useDefault: {
Errors:
wrongConcreteType: cannot use 2 (type int) as type bool:
./in.cue:4:2
./in.cue:1:9
wrongType: cannot use int (type int) as type bool:
./in.cue:10:2

Expand All @@ -127,6 +128,7 @@ Result:
wrongConcreteType: (_|_){
// [eval] wrongConcreteType: cannot use 2 (type int) as type bool:
// ./in.cue:4:2
// ./in.cue:1:9
}
wrongType: (_|_){
// [eval] wrongType: cannot use int (type int) as type bool:
Expand Down
6 changes: 6 additions & 0 deletions cue/testdata/cycle/023_reentrance.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,21 @@ Result:
out: (_|_){
// [incomplete] non-concrete value int in operand to >=:
// ./in.cue:7:5
// ./in.cue:3:32
// ./in.cue:5:2
// non-concrete value int in operand to <:
// ./in.cue:10:5
// ./in.cue:3:32
// ./in.cue:5:2
}
}
fib: (_|_){
// [incomplete] fib: non-concrete value int in operand to >=:
// ./in.cue:7:5
// ./in.cue:5:2
// fib: non-concrete value int in operand to <:
// ./in.cue:10:5
// ./in.cue:5:2
n: (int){ int }
}
fib2: (int){ 1 }
Expand Down
Loading

0 comments on commit 276ce26

Please sign in to comment.