Skip to content

Commit

Permalink
internal/core/eval: sort empty disjunction message to top of group
Browse files Browse the repository at this point in the history
By adding leading with the number, which sorts before
any letter.

Change-Id: I8027f61e74e7ca206ec78dfdbbe7534d21ef1cc5
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8042
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Jan 2, 2021
1 parent 0ef6caa commit 062b3d8
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 40 deletions.
2 changes: 1 addition & 1 deletion cmd/cue/cmd/testdata/script/eval_errs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmp stdout expect-stdout

-- expect-stdout --
-- expect-stderr --
bar: empty disjunction: 2 related errors:
bar: 2 errors in empty disjunction:
bar.a: conflicting values "str" and int (mismatched types string and int):
./errs.cue:5:10
./errs.cue:6:6
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/benchmarks/dedupelem.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ foo: [{type: "float"}] & [...#Value]
foo: [{type: "float"}] & [...#Value]
-- out/eval --
Errors:
foo.0: empty disjunction: 2 related errors:
foo.0: 2 errors in empty disjunction:
foo.0.type: conflicting values "int" and "float":
./in.cue:3:16
./in.cue:5:14
Expand All @@ -37,7 +37,7 @@ Result:
foo: (_|_){
// [eval]
0: (_|_){
// [eval] foo.0: empty disjunction: 2 related errors:
// [eval] foo.0: 2 errors in empty disjunction:
// foo.0.type: conflicting values "int" and "float":
// ./in.cue:3:16
// ./in.cue:5:14
Expand Down
10 changes: 5 additions & 5 deletions cue/testdata/cycle/issue429.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ er3: #nonEmptyRange & {

-- out/eval --
Errors:
er3.min: empty disjunction: 1 related errors:
es3.max: empty disjunction: 1 related errors:
er3.min: 1 errors in empty disjunction:
es3.max: 1 errors in empty disjunction:
es3.max: invalid value 5 (out of bound >10):
./in.cue:5:10
./in.cue:22:10
Expand Down Expand Up @@ -94,7 +94,7 @@ Result:
res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
min: (int){ 10 }
max: (_|_){
// [eval] es3.max: empty disjunction: 1 related errors:
// [eval] es3.max: 1 errors in empty disjunction:
// es3.max: invalid value 5 (out of bound >10):
// ./in.cue:5:10
// ./in.cue:22:10
Expand Down Expand Up @@ -123,13 +123,13 @@ Result:
er3: (_|_){
// [eval]
min: (_|_){
// [eval] er3.min: empty disjunction: 1 related errors:
// [eval] er3.min: 1 errors in empty disjunction:
// er3.min: invalid value 5 (out of bound <5):
// ./in.cue:29:10
// ./in.cue:44:10
}
max: (_|_){
// [eval] er3.min: empty disjunction: 1 related errors:
// [eval] er3.min: 1 errors in empty disjunction:
// er3.min: invalid value 5 (out of bound <5):
// ./in.cue:29:10
// ./in.cue:44:10
Expand Down
20 changes: 10 additions & 10 deletions cue/testdata/cycle/structural.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -440,30 +440,30 @@ e3.b.c: conflicting values [b] and {c:b} (mismatched types list and struct):
./in.cue:293:8
./in.cue:293:11
e3.b.c: structural cycle
e4.a.0: 4 errors in empty disjunction:
e4.a.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
./in.cue:297:13
./in.cue:298:9
e4.a.0: empty disjunction: 4 related errors:
e4.a.0.0: 2 errors in empty disjunction:
e4.a.0.0: conflicting values [{c:1}] and {c:1} (mismatched types list and struct):
./in.cue:298:9
./in.cue:298:10
e4.a.0.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
./in.cue:297:9
./in.cue:297:13
./in.cue:298:9
e4.a.0.0: empty disjunction: 2 related errors:
e4.b.0: 4 errors in empty disjunction:
e4.b.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
./in.cue:300:9
./in.cue:301:13
e4.b.0: empty disjunction: 4 related errors:
e4.b.0.0: 2 errors in empty disjunction:
e4.b.0.0: conflicting values [{c:1}] and {c:1} (mismatched types list and struct):
./in.cue:300:9
./in.cue:300:10
e4.b.0.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
./in.cue:300:9
./in.cue:301:9
./in.cue:301:13
e4.b.0.0: empty disjunction: 2 related errors:
p2.#T.a.b.link: structural cycle
p3.#U.#T.a.b.link: structural cycle
p5.#T.a.0.link: structural cycle
Expand Down Expand Up @@ -1212,18 +1212,18 @@ Result:
a: (_|_){
// [eval]
0: (_|_){
// [eval] e4.a.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
// [eval] e4.a.0: 4 errors in empty disjunction:
// e4.a.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
// ./in.cue:297:13
// ./in.cue:298:9
// e4.a.0: empty disjunction: 4 related errors:
// e4.a.0.0: 2 errors in empty disjunction:
// e4.a.0.0: conflicting values [{c:1}] and {c:1} (mismatched types list and struct):
// ./in.cue:298:9
// ./in.cue:298:10
// e4.a.0.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
// ./in.cue:297:9
// ./in.cue:297:13
// ./in.cue:298:9
// e4.a.0.0: empty disjunction: 2 related errors:
0: (struct){
c: (int){ 1 }
}
Expand All @@ -1232,18 +1232,18 @@ Result:
b: (_|_){
// [eval]
0: (_|_){
// [eval] e4.b.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
// [eval] e4.b.0: 4 errors in empty disjunction:
// e4.b.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
// ./in.cue:300:9
// ./in.cue:301:13
// e4.b.0: empty disjunction: 4 related errors:
// e4.b.0.0: 2 errors in empty disjunction:
// e4.b.0.0: conflicting values [{c:1}] and {c:1} (mismatched types list and struct):
// ./in.cue:300:9
// ./in.cue:300:10
// e4.b.0.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
// ./in.cue:300:9
// ./in.cue:301:9
// ./in.cue:301:13
// e4.b.0.0: empty disjunction: 2 related errors:
0: (struct){
c: (int){ 1 }
}
Expand Down
8 changes: 4 additions & 4 deletions cue/testdata/disjunctions/errors.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ explicitDefaultError: {

-- out/eval --
Errors:
issue516.x: empty disjunction: 2 related errors:
issue516.x: 2 errors in empty disjunction:
issue516.x: field `match` not allowed:
./in.cue:20:9
./in.cue:22:8
Expand All @@ -43,7 +43,7 @@ issue516.x.match.metrics: field `foo` not allowed:
./in.cue:19:25
./in.cue:22:8
./in.cue:23:24
issue570.results: empty disjunction: 2 related errors:
issue570.results: 2 errors in empty disjunction:
issue570.results: field `result` not allowed:
./in.cue:2:14
./in.cue:3:14
Expand All @@ -61,7 +61,7 @@ Result:
issue570: (_|_){
// [eval]
results: (_|_){
// [eval] issue570.results: empty disjunction: 2 related errors:
// [eval] issue570.results: 2 errors in empty disjunction:
// issue570.results: field `result` not allowed:
// ./in.cue:2:14
// ./in.cue:3:14
Expand Down Expand Up @@ -106,7 +106,7 @@ Result:
}, (#struct){
}) }
x: (_|_){
// [eval] issue516.x: empty disjunction: 2 related errors:
// [eval] issue516.x: 2 errors in empty disjunction:
// issue516.x: field `match` not allowed:
// ./in.cue:20:9
// ./in.cue:22:8
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/eval/closed_disjunction.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ b: #A & {
}
-- out/eval --
Errors:
b: empty disjunction: 2 related errors:
b: 2 errors in empty disjunction:
b: field `c` not allowed:
./in.cue:1:5
./in.cue:3:5
Expand All @@ -39,7 +39,7 @@ Result:
c: (int){ 3 }
}
b: (_|_){
// [eval] b: empty disjunction: 2 related errors:
// [eval] b: 2 errors in empty disjunction:
// b: field `c` not allowed:
// ./in.cue:1:5
// ./in.cue:3:5
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/eval/disjunctions.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ d100: {

-- out/eval --
Errors:
f: empty disjunction: 2 related errors:
f: 2 errors in empty disjunction:
f.name: conflicting values "int" and "str":
./in.cue:5:8
./in.cue:15:4
Expand Down Expand Up @@ -96,7 +96,7 @@ Result:
name: (string){ "str" }
}
f: (_|_){
// [eval] f: empty disjunction: 2 related errors:
// [eval] f: 2 errors in empty disjunction:
// f.name: conflicting values "int" and "str":
// ./in.cue:5:8
// ./in.cue:15:4
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/fulleval/024_Issue_#23.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ y: _|_ // ; empty disjunction: conflicting values 2 and 3
}
-- out/eval --
Errors:
y: empty disjunction: 2 related errors:
y: 2 errors in empty disjunction:
y.a: conflicting values 1 and 3:
./in.cue:1:12
./in.cue:2:4
Expand All @@ -47,7 +47,7 @@ Result:
a: (int){ 2 }
}) }
y: (_|_){
// [eval] y: empty disjunction: 2 related errors:
// [eval] y: 2 errors in empty disjunction:
// y.a: conflicting values 1 and 3:
// ./in.cue:1:12
// ./in.cue:2:4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ a.v: field `b` not allowed:
./in.cue:2:12
./in.cue:4:4
./in.cue:5:6
b.w: empty disjunction: 1 related errors:
b.w: 1 errors in empty disjunction:
b.w: field `c` not allowed:
./in.cue:8:12
./in.cue:10:4
Expand Down Expand Up @@ -141,7 +141,7 @@ Result:
b: (_|_){
// [eval]
w: (_|_){
// [eval] b.w: empty disjunction: 1 related errors:
// [eval] b.w: 1 errors in empty disjunction:
// b.w: field `c` not allowed:
// ./in.cue:8:12
// ./in.cue:10:4
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/resolve/030_definitions_with_disjunctions.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ baz: #Foo & {
}
-- out/eval --
Errors:
bar: empty disjunction: 1 related errors:
bar: 1 errors in empty disjunction:
bar: field `c` not allowed:
./in.cue:1:7
./in.cue:4:2
Expand All @@ -83,7 +83,7 @@ Result:
a: (int){ 1 }
}
bar: (_|_){
// [eval] bar: empty disjunction: 1 related errors:
// [eval] bar: 1 errors in empty disjunction:
// bar: field `c` not allowed:
// ./in.cue:1:7
// ./in.cue:4:2
Expand Down
6 changes: 3 additions & 3 deletions cuego/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func ExampleComplete_structTag() {
//Output:
// completed: cuego_test.Sum{A:1, B:5, C:6} (err: <nil>)
// completed: cuego_test.Sum{A:2, B:6, C:8} (err: <nil>)
// empty disjunction: 2 related errors:
// 2 errors in empty disjunction:
// conflicting values null and {A:2,B:3,C:8} (mismatched types null and struct)
// A: conflicting values 5 and 2
}
Expand Down Expand Up @@ -97,10 +97,10 @@ func ExampleConstrain() {
//Output:
// error: nil
// validate: nil
// validate: empty disjunction: 2 related errors:
// validate: 2 errors in empty disjunction:
// conflicting values null and {Filename:"foo.json",MaxCount:12,MinCount:39} (mismatched types null and struct)
// MinCount: invalid value 39 (out of bound <=12)
// validate: empty disjunction: 2 related errors:
// validate: 2 errors in empty disjunction:
// conflicting values null and {Filename:"foo.jso",MaxCount:120,MinCount:39} (mismatched types null and struct)
// Filename: invalid value "foo.jso" (out of bound =~".json$")
}
Expand Down
3 changes: 2 additions & 1 deletion internal/core/eval/disjunct.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ func (n *nodeContext) disjunctError() (errs errors.Error) {
} else {
disjuncts = errors.Sanitize(disjuncts)
k := len(errors.Errors(disjuncts))
errs = ctx.Newf("empty disjunction: %d related errors:", k)
// prefix '-' to sort to top
errs = ctx.Newf("%d errors in empty disjunction:", k)
}

errs = errors.Append(errs, disjuncts)
Expand Down
8 changes: 4 additions & 4 deletions pkg/list/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ error in call to list.Slice: negative index
error in call to list.Slice: slice bounds out of range
error in call to list.Take: negative index
0: error in call to list.SortStrings: element 0 of list argument 0: cannot use value 1 (type int) as string
Ascending.x: error in call to list.Sort: 2 errors in empty disjunction:
Ascending.x: error in call to list.Sort: conflicting values number and {b:2} (mismatched types number and struct)
Ascending.x: error in call to list.Sort: conflicting values string and {b:2} (mismatched types string and struct)
Ascending.x: error in call to list.Sort: empty disjunction: 2 related errors:
Ascending.y: error in call to list.Sort: 2 errors in empty disjunction:
Ascending.y: error in call to list.Sort: conflicting values number and {a:1} (mismatched types number and struct)
Ascending.y: error in call to list.Sort: conflicting values string and {a:1} (mismatched types string and struct)
Ascending.y: error in call to list.Sort: empty disjunction: 2 related errors:
t3: cannot use "foo" (type string) as list in argument 1 to list.Avg:
./in.cue:5:14
t14: cannot use "foo" (type string) as int in argument 2 to list.FlattenN:
Expand Down Expand Up @@ -144,7 +144,7 @@ t39: [{
a: 2
v: 1
}]
t40: _|_ // error in call to list.Sort: Ascending.x: empty disjunction: 2 related errors: (and 11 more errors)
t40: _|_ // error in call to list.Sort: Ascending.x: 2 errors in empty disjunction: (and 11 more errors)
t41: ["a", "b"]
t42: _|_ // error in call to list.SortStrings: element 0 of list argument 0: 0: cannot use value 1 (type int) as string (and 1 more errors)
t43: 10
Expand All @@ -158,5 +158,5 @@ t50: true
t51: false
t52: true
t53: false
t54: _|_ // error in call to list.Sort: Ascending.x: empty disjunction: 2 related errors: (and 11 more errors)
t54: _|_ // error in call to list.Sort: Ascending.x: 2 errors in empty disjunction: (and 11 more errors)

0 comments on commit 062b3d8

Please sign in to comment.