Skip to content

Commit 908614e

Browse files
committed
internal/core/adt: dedup errors
Change-Id: I335f7d22c76fb16200b98f9c1f3c7e3712b267aa Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9448 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent dcb2a1f commit 908614e

File tree

15 files changed

+48
-46
lines changed

15 files changed

+48
-46
lines changed

cue/builtin_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ func TestBuiltins(t *testing.T) {
6262
`16`,
6363
}, {
6464
test("encoding/yaml", `yaml.Validate("a: 2\n---\na: 4", {a:<3})`),
65-
`_|_(error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3) (and 1 more errors))`,
65+
`_|_(error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3))`,
6666
}, {
6767
test("encoding/yaml", `yaml.Validate("a: 2\n---\na: 4", {a:<5})`),
6868
`true`,
6969
}, {
7070
test("encoding/yaml", `yaml.Validate("a: 2\n", {a:<5, b:int})`),
71-
`_|_(error in call to encoding/yaml.Validate: b: incomplete value int (and 1 more errors))`,
71+
`_|_(error in call to encoding/yaml.Validate: b: incomplete value int)`,
7272
}, {
7373
test("strconv", `strconv.FormatUint(64, 16)`),
7474
`"40"`,
@@ -77,7 +77,7 @@ func TestBuiltins(t *testing.T) {
7777
`"foo"`,
7878
}, {
7979
test("regexp", `regexp.Find(#"f\w\w"#, "bar")`),
80-
`_|_(error in call to regexp.Find: no match (and 1 more errors))`,
80+
`_|_(error in call to regexp.Find: no match)`,
8181
}, {
8282
testExpr(`len([1, 2, 3])`),
8383
`3`,
@@ -92,7 +92,7 @@ func TestBuiltins(t *testing.T) {
9292
x: int
9393
y: json.Marshal({a: x})
9494
}`),
95-
`{x:int,y:_|_(cannot convert incomplete value "int" to JSON (and 1 more errors))}`,
95+
`{x:int,y:_|_(cannot convert incomplete value "int" to JSON)}`,
9696
}, {
9797
test("encoding/yaml", `yaml.MarshalStream([{a: 1}, {b: 2}])`),
9898
`"a: 1\n---\nb: 2\n"`,
@@ -146,7 +146,7 @@ func TestSingleBuiltin(t *testing.T) {
146146
emit string
147147
}{{
148148
test("list", `list.Sort([{a:1}, {b:2}], list.Ascending)`),
149-
`_|_(error in call to list.Sort: less: invalid operands {b:2} and {a:1} to '<' (type struct and struct) (and 1 more errors))`,
149+
`_|_(error in call to list.Sort: less: invalid operands {b:2} and {a:1} to '<' (type struct and struct))`,
150150
}}
151151
for i, tc := range testCases {
152152
t.Run(fmt.Sprint(i), func(t *testing.T) {

internal/core/adt/context.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,9 @@ func (c *OpContext) evalState(v Expr, state VertexStatus) (result Value) {
591591
bb.Err = errors.Wrapf(b.Err, c.src.Pos(), "")
592592
result = &bb
593593
}
594-
c.errs = CombineErrors(c.src, c.errs, result)
594+
if c.errs != result {
595+
c.errs = CombineErrors(c.src, c.errs, result)
596+
}
595597
}
596598
if c.errs != nil {
597599
result = c.errs

pkg/encoding/base64/testdata/gen.txtar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ error in call to encoding/base64.Decode: illegal base64 data at input byte 0
1515
Result:
1616
t1: "Zm9v"
1717
t2: 'foo'
18-
t3: _|_ // error in call to encoding/base64.Decode: illegal base64 data at input byte 0 (and 1 more errors)
19-
t4: _|_ // error in call to encoding/base64.Decode: base64: unsupported encoding: cannot use value {} (type struct) as null (and 1 more errors)
18+
t3: _|_ // error in call to encoding/base64.Decode: illegal base64 data at input byte 0
19+
t4: _|_ // error in call to encoding/base64.Decode: base64: unsupported encoding: cannot use value {} (type struct) as null
2020

pkg/encoding/hex/testdata/gen.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o'
1414
Result:
1515
t1: "666f6f"
1616
t2: 'foo'
17-
t3: _|_ // error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o' (and 1 more errors)
17+
t3: _|_ // error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o'
1818
t4: """
1919
00000000 66 6f 6f |foo|
2020

pkg/encoding/json/testdata/gen.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Result:
2525
import "encoding/json"
2626

2727
t1: true
28-
t2: _|_ // error in call to encoding/json.Validate: a: invalid value 10 (out of bound <3) (and 1 more errors)
28+
t2: _|_ // error in call to encoding/json.Validate: a: invalid value 10 (out of bound <3)
2929
t3: true
3030
t4: "[1,2]"
3131
t5: """

pkg/encoding/yaml/testdata/gen.txtar

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ a: error in call to encoding/yaml.ValidatePartial: invalid value 4 (out of bound
2323
yaml.ValidatePartial:3:5
2424

2525
Result:
26-
t1: _|_ // error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3) (and 1 more errors)
26+
t1: _|_ // error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3)
2727
t2: true
28-
t3: _|_ // error in call to encoding/yaml.Validate: b: incomplete value int (and 1 more errors)
29-
t4: _|_ // error in call to encoding/yaml.ValidatePartial: a: invalid value 4 (out of bound <3) (and 1 more errors)
28+
t3: _|_ // error in call to encoding/yaml.Validate: b: incomplete value int
29+
t4: _|_ // error in call to encoding/yaml.ValidatePartial: a: invalid value 4 (out of bound <3)
3030
t5: true
3131
t6: true
3232
t7: """

pkg/list/testdata/gen.txtar

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ Ascending.x: error in call to list.Sort: conflicting values number and {b:2} (mi
7979
./in.cue:46:24
8080
list:10:9
8181
Ascending.x: error in call to list.Sort: conflicting values string and {b:2} (mismatched types string and struct):
82-
./in.cue:46:24
82+
./in.cue:60:24
8383
list:10:18
8484
Ascending.y: error in call to list.Sort: 2 errors in empty disjunction:
8585
Ascending.y: error in call to list.Sort: conflicting values number and {a:1} (mismatched types number and struct):
86-
./in.cue:46:17
86+
./in.cue:60:17
8787
list:10:9
8888
Ascending.y: error in call to list.Sort: conflicting values string and {a:1} (mismatched types string and struct):
89-
./in.cue:60:17
89+
./in.cue:46:17
9090
list:10:18
9191
t3: cannot use "foo" (type string) as list in argument 1 to list.Avg:
9292
./in.cue:5:14
@@ -107,41 +107,41 @@ t45: cannot use "foo" (type string) as list in argument 1 to list.Sum:
107107

108108
Result:
109109
t1: 2.5
110-
t2: _|_ // error in call to list.Avg: empty list (and 1 more errors)
110+
t2: _|_ // error in call to list.Avg: empty list
111111
t3: _|_ // t3: cannot use "foo" (type string) as list in argument 1 to list.Avg
112112
t4: [1, 2, 3, 4]
113113
t5: [3, 4]
114114
t6: []
115-
t7: _|_ // error in call to list.Drop: negative index (and 1 more errors)
115+
t7: _|_ // error in call to list.Drop: negative index
116116
t8: [1, 2, 3, 4]
117117
t9: [1, [[2, 3], []], [4]]
118118
t10: [1, [2, 3], [], 4]
119119
t11: [1, 2, 3, 4]
120120
t12: []
121-
t13: _|_ // error in call to list.FlattenN: cannot use value "foo" (type string) as list (and 1 more errors)
121+
t13: _|_ // error in call to list.FlattenN: cannot use value "foo" (type string) as list
122122
t14: _|_ // t14: cannot use "foo" (type string) as int in argument 2 to list.FlattenN
123123
t15: 4
124-
t16: _|_ // error in call to list.Max: empty list (and 1 more errors)
124+
t16: _|_ // error in call to list.Max: empty list
125125
t17: _|_ // t17: cannot use "foo" (type string) as list in argument 1 to list.Max
126126
t18: 1
127-
t19: _|_ // error in call to list.Min: empty list (and 1 more errors)
127+
t19: _|_ // error in call to list.Min: empty list
128128
t20: _|_ // t20: cannot use "foo" (type string) as list in argument 1 to list.Min
129129
t21: 24
130130
t22: 1
131131
t23: _|_ // t23: cannot use "foo" (type string) as list in argument 1 to list.Product
132-
t24: _|_ // error in call to list.Range: step must be non zero (and 1 more errors)
133-
t25: _|_ // error in call to list.Range: end must be greater than start when step is positive (and 1 more errors)
134-
t26: _|_ // error in call to list.Range: end must be less than start when step is negative (and 1 more errors)
132+
t24: _|_ // error in call to list.Range: step must be non zero
133+
t25: _|_ // error in call to list.Range: end must be greater than start when step is positive
134+
t26: _|_ // error in call to list.Range: end must be less than start when step is negative
135135
t27: [0, 1, 2, 3, 4]
136136
t28: [0]
137137
t29: [0, 2, 4]
138138
t30: [5, 4, 3, 2, 1]
139139
t31: [0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
140140
t32: [2, 3]
141-
t33: _|_ // error in call to list.Slice: negative index (and 1 more errors)
142-
t34: _|_ // error in call to list.Slice: invalid index: 3 > 1 (and 1 more errors)
143-
t35: _|_ // error in call to list.Slice: slice bounds out of range (and 1 more errors)
144-
t36: _|_ // error in call to list.Slice: slice bounds out of range (and 1 more errors)
141+
t33: _|_ // error in call to list.Slice: negative index
142+
t34: _|_ // error in call to list.Slice: invalid index: 3 > 1
143+
t35: _|_ // error in call to list.Slice: slice bounds out of range
144+
t36: _|_ // error in call to list.Slice: slice bounds out of range
145145
t37: []
146146
t38: [1, 2, 3, 4]
147147
t39: [{
@@ -154,19 +154,19 @@ t39: [{
154154
a: 2
155155
v: 1
156156
}]
157-
t40: _|_ // error in call to list.Sort: Ascending.x: 2 errors in empty disjunction: (and 11 more errors)
157+
t40: _|_ // error in call to list.Sort: Ascending.x: 2 errors in empty disjunction: (and 5 more errors)
158158
t41: ["a", "b"]
159-
t42: _|_ // t42: invalid type element 0 (int) of string list argument 0 (and 1 more errors)
159+
t42: _|_ // t42: invalid type element 0 (int) of string list argument 0
160160
t43: 10
161161
t44: 0
162162
t45: _|_ // t45: cannot use "foo" (type string) as list in argument 1 to list.Sum
163163
t46: []
164164
t47: [1, 2]
165165
t48: [1, 2, 3, 4]
166-
t49: _|_ // error in call to list.Take: negative index (and 1 more errors)
166+
t49: _|_ // error in call to list.Take: negative index
167167
t50: true
168168
t51: false
169169
t52: true
170170
t53: false
171-
t54: _|_ // error in call to list.Sort: Ascending.x: 2 errors in empty disjunction: (and 11 more errors)
171+
t54: _|_ // error in call to list.Sort: Ascending.x: 2 errors in empty disjunction: (and 5 more errors)
172172

pkg/list/testdata/list.txtar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ repeat: {
8989
t8: {
9090
x: [1]
9191
n: -1
92-
v: _|_ // error in call to list.Repeat: negative count (and 1 more errors)
92+
v: _|_ // error in call to list.Repeat: negative count
9393
}
9494
}
9595
concat: {
@@ -123,7 +123,7 @@ concat: {
123123
}
124124
t8: {
125125
x: [1, [2]]
126-
v: _|_ // error in call to list.Concat: cannot use value 1 (type int) as list (and 1 more errors)
126+
v: _|_ // error in call to list.Concat: cannot use value 1 (type int) as list
127127
}
128128
}
129129
unique: {

pkg/math/testdata/gen.txtar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ Result:
3636
t1: 3.14159265358979323846264338327950288419716939937510582097494459
3737
t2: 3
3838
t3: _|_ // t3: cannot call non-function math.Pi (type float)
39-
t6: _|_ // error in call to math.Jacobi: big: invalid 2nd argument to Int.Jacobi: need odd integer but got 2000 (and 1 more errors)
39+
t6: _|_ // error in call to math.Jacobi: big: invalid 2nd argument to Int.Jacobi: need odd integer but got 2000
4040
t7: 1
41-
t8: _|_ // cannot use 2.0E+400 (type float) as float64 in argument 0 to math.Asin: value was rounded up (and 1 more errors)
41+
t8: _|_ // cannot use 2.0E+400 (type float) as float64 in argument 0 to math.Asin: value was rounded up
4242
t16: 4096
4343
t17: 1e+4
4444
t18: true

pkg/math/testdata/round.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Result:
4444
mul0: true
4545
mul1: false
4646
// TODO(errors): ensure path is included for the following error.
47-
mul2: _|_ // error in call to math.MultipleOf: division by zero (and 1 more errors)
47+
mul2: _|_ // error in call to math.MultipleOf: division by zero
4848
mul3: false
4949
mul4: true
5050
mul5: true

0 commit comments

Comments
 (0)