Skip to content

Commit

Permalink
internal/core/adt: dedup errors
Browse files Browse the repository at this point in the history
Change-Id: I335f7d22c76fb16200b98f9c1f3c7e3712b267aa
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9448
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
  • Loading branch information
mpvl committed Apr 20, 2021
1 parent dcb2a1f commit 908614e
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 46 deletions.
10 changes: 5 additions & 5 deletions cue/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ func TestBuiltins(t *testing.T) {
`16`,
}, {
test("encoding/yaml", `yaml.Validate("a: 2\n---\na: 4", {a:<3})`),
`_|_(error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3) (and 1 more errors))`,
`_|_(error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3))`,
}, {
test("encoding/yaml", `yaml.Validate("a: 2\n---\na: 4", {a:<5})`),
`true`,
}, {
test("encoding/yaml", `yaml.Validate("a: 2\n", {a:<5, b:int})`),
`_|_(error in call to encoding/yaml.Validate: b: incomplete value int (and 1 more errors))`,
`_|_(error in call to encoding/yaml.Validate: b: incomplete value int)`,
}, {
test("strconv", `strconv.FormatUint(64, 16)`),
`"40"`,
Expand All @@ -77,7 +77,7 @@ func TestBuiltins(t *testing.T) {
`"foo"`,
}, {
test("regexp", `regexp.Find(#"f\w\w"#, "bar")`),
`_|_(error in call to regexp.Find: no match (and 1 more errors))`,
`_|_(error in call to regexp.Find: no match)`,
}, {
testExpr(`len([1, 2, 3])`),
`3`,
Expand All @@ -92,7 +92,7 @@ func TestBuiltins(t *testing.T) {
x: int
y: json.Marshal({a: x})
}`),
`{x:int,y:_|_(cannot convert incomplete value "int" to JSON (and 1 more errors))}`,
`{x:int,y:_|_(cannot convert incomplete value "int" to JSON)}`,
}, {
test("encoding/yaml", `yaml.MarshalStream([{a: 1}, {b: 2}])`),
`"a: 1\n---\nb: 2\n"`,
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestSingleBuiltin(t *testing.T) {
emit string
}{{
test("list", `list.Sort([{a:1}, {b:2}], list.Ascending)`),
`_|_(error in call to list.Sort: less: invalid operands {b:2} and {a:1} to '<' (type struct and struct) (and 1 more errors))`,
`_|_(error in call to list.Sort: less: invalid operands {b:2} and {a:1} to '<' (type struct and struct))`,
}}
for i, tc := range testCases {
t.Run(fmt.Sprint(i), func(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion internal/core/adt/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,9 @@ func (c *OpContext) evalState(v Expr, state VertexStatus) (result Value) {
bb.Err = errors.Wrapf(b.Err, c.src.Pos(), "")
result = &bb
}
c.errs = CombineErrors(c.src, c.errs, result)
if c.errs != result {
c.errs = CombineErrors(c.src, c.errs, result)
}
}
if c.errs != nil {
result = c.errs
Expand Down
4 changes: 2 additions & 2 deletions pkg/encoding/base64/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ error in call to encoding/base64.Decode: illegal base64 data at input byte 0
Result:
t1: "Zm9v"
t2: 'foo'
t3: _|_ // error in call to encoding/base64.Decode: illegal base64 data at input byte 0 (and 1 more errors)
t4: _|_ // error in call to encoding/base64.Decode: base64: unsupported encoding: cannot use value {} (type struct) as null (and 1 more errors)
t3: _|_ // error in call to encoding/base64.Decode: illegal base64 data at input byte 0
t4: _|_ // error in call to encoding/base64.Decode: base64: unsupported encoding: cannot use value {} (type struct) as null

2 changes: 1 addition & 1 deletion pkg/encoding/hex/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o'
Result:
t1: "666f6f"
t2: 'foo'
t3: _|_ // error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o' (and 1 more errors)
t3: _|_ // error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o'
t4: """
00000000 66 6f 6f |foo|

Expand Down
2 changes: 1 addition & 1 deletion pkg/encoding/json/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Result:
import "encoding/json"

t1: true
t2: _|_ // error in call to encoding/json.Validate: a: invalid value 10 (out of bound <3) (and 1 more errors)
t2: _|_ // error in call to encoding/json.Validate: a: invalid value 10 (out of bound <3)
t3: true
t4: "[1,2]"
t5: """
Expand Down
6 changes: 3 additions & 3 deletions pkg/encoding/yaml/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ a: error in call to encoding/yaml.ValidatePartial: invalid value 4 (out of bound
yaml.ValidatePartial:3:5

Result:
t1: _|_ // error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3) (and 1 more errors)
t1: _|_ // error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3)
t2: true
t3: _|_ // error in call to encoding/yaml.Validate: b: incomplete value int (and 1 more errors)
t4: _|_ // error in call to encoding/yaml.ValidatePartial: a: invalid value 4 (out of bound <3) (and 1 more errors)
t3: _|_ // error in call to encoding/yaml.Validate: b: incomplete value int
t4: _|_ // error in call to encoding/yaml.ValidatePartial: a: invalid value 4 (out of bound <3)
t5: true
t6: true
t7: """
Expand Down
38 changes: 19 additions & 19 deletions pkg/list/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ Ascending.x: error in call to list.Sort: conflicting values number and {b:2} (mi
./in.cue:46:24
list:10:9
Ascending.x: error in call to list.Sort: conflicting values string and {b:2} (mismatched types string and struct):
./in.cue:46:24
./in.cue:60:24
list:10:18
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):
./in.cue:46:17
./in.cue:60:17
list:10:9
Ascending.y: error in call to list.Sort: conflicting values string and {a:1} (mismatched types string and struct):
./in.cue:60:17
./in.cue:46:17
list:10:18
t3: cannot use "foo" (type string) as list in argument 1 to list.Avg:
./in.cue:5:14
Expand All @@ -107,41 +107,41 @@ t45: cannot use "foo" (type string) as list in argument 1 to list.Sum:

Result:
t1: 2.5
t2: _|_ // error in call to list.Avg: empty list (and 1 more errors)
t2: _|_ // error in call to list.Avg: empty list
t3: _|_ // t3: cannot use "foo" (type string) as list in argument 1 to list.Avg
t4: [1, 2, 3, 4]
t5: [3, 4]
t6: []
t7: _|_ // error in call to list.Drop: negative index (and 1 more errors)
t7: _|_ // error in call to list.Drop: negative index
t8: [1, 2, 3, 4]
t9: [1, [[2, 3], []], [4]]
t10: [1, [2, 3], [], 4]
t11: [1, 2, 3, 4]
t12: []
t13: _|_ // error in call to list.FlattenN: cannot use value "foo" (type string) as list (and 1 more errors)
t13: _|_ // error in call to list.FlattenN: cannot use value "foo" (type string) as list
t14: _|_ // t14: cannot use "foo" (type string) as int in argument 2 to list.FlattenN
t15: 4
t16: _|_ // error in call to list.Max: empty list (and 1 more errors)
t16: _|_ // error in call to list.Max: empty list
t17: _|_ // t17: cannot use "foo" (type string) as list in argument 1 to list.Max
t18: 1
t19: _|_ // error in call to list.Min: empty list (and 1 more errors)
t19: _|_ // error in call to list.Min: empty list
t20: _|_ // t20: cannot use "foo" (type string) as list in argument 1 to list.Min
t21: 24
t22: 1
t23: _|_ // t23: cannot use "foo" (type string) as list in argument 1 to list.Product
t24: _|_ // error in call to list.Range: step must be non zero (and 1 more errors)
t25: _|_ // error in call to list.Range: end must be greater than start when step is positive (and 1 more errors)
t26: _|_ // error in call to list.Range: end must be less than start when step is negative (and 1 more errors)
t24: _|_ // error in call to list.Range: step must be non zero
t25: _|_ // error in call to list.Range: end must be greater than start when step is positive
t26: _|_ // error in call to list.Range: end must be less than start when step is negative
t27: [0, 1, 2, 3, 4]
t28: [0]
t29: [0, 2, 4]
t30: [5, 4, 3, 2, 1]
t31: [0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
t32: [2, 3]
t33: _|_ // error in call to list.Slice: negative index (and 1 more errors)
t34: _|_ // error in call to list.Slice: invalid index: 3 > 1 (and 1 more errors)
t35: _|_ // error in call to list.Slice: slice bounds out of range (and 1 more errors)
t36: _|_ // error in call to list.Slice: slice bounds out of range (and 1 more errors)
t33: _|_ // error in call to list.Slice: negative index
t34: _|_ // error in call to list.Slice: invalid index: 3 > 1
t35: _|_ // error in call to list.Slice: slice bounds out of range
t36: _|_ // error in call to list.Slice: slice bounds out of range
t37: []
t38: [1, 2, 3, 4]
t39: [{
Expand All @@ -154,19 +154,19 @@ t39: [{
a: 2
v: 1
}]
t40: _|_ // error in call to list.Sort: Ascending.x: 2 errors in empty disjunction: (and 11 more errors)
t40: _|_ // error in call to list.Sort: Ascending.x: 2 errors in empty disjunction: (and 5 more errors)
t41: ["a", "b"]
t42: _|_ // t42: invalid type element 0 (int) of string list argument 0 (and 1 more errors)
t42: _|_ // t42: invalid type element 0 (int) of string list argument 0
t43: 10
t44: 0
t45: _|_ // t45: cannot use "foo" (type string) as list in argument 1 to list.Sum
t46: []
t47: [1, 2]
t48: [1, 2, 3, 4]
t49: _|_ // error in call to list.Take: negative index (and 1 more errors)
t49: _|_ // error in call to list.Take: negative index
t50: true
t51: false
t52: true
t53: false
t54: _|_ // error in call to list.Sort: Ascending.x: 2 errors in empty disjunction: (and 11 more errors)
t54: _|_ // error in call to list.Sort: Ascending.x: 2 errors in empty disjunction: (and 5 more errors)

4 changes: 2 additions & 2 deletions pkg/list/testdata/list.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ repeat: {
t8: {
x: [1]
n: -1
v: _|_ // error in call to list.Repeat: negative count (and 1 more errors)
v: _|_ // error in call to list.Repeat: negative count
}
}
concat: {
Expand Down Expand Up @@ -123,7 +123,7 @@ concat: {
}
t8: {
x: [1, [2]]
v: _|_ // error in call to list.Concat: cannot use value 1 (type int) as list (and 1 more errors)
v: _|_ // error in call to list.Concat: cannot use value 1 (type int) as list
}
}
unique: {
Expand Down
4 changes: 2 additions & 2 deletions pkg/math/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ Result:
t1: 3.14159265358979323846264338327950288419716939937510582097494459
t2: 3
t3: _|_ // t3: cannot call non-function math.Pi (type float)
t6: _|_ // error in call to math.Jacobi: big: invalid 2nd argument to Int.Jacobi: need odd integer but got 2000 (and 1 more errors)
t6: _|_ // error in call to math.Jacobi: big: invalid 2nd argument to Int.Jacobi: need odd integer but got 2000
t7: 1
t8: _|_ // cannot use 2.0E+400 (type float) as float64 in argument 0 to math.Asin: value was rounded up (and 1 more errors)
t8: _|_ // cannot use 2.0E+400 (type float) as float64 in argument 0 to math.Asin: value was rounded up
t16: 4096
t17: 1e+4
t18: true
Expand Down
2 changes: 1 addition & 1 deletion pkg/math/testdata/round.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Result:
mul0: true
mul1: false
// TODO(errors): ensure path is included for the following error.
mul2: _|_ // error in call to math.MultipleOf: division by zero (and 1 more errors)
mul2: _|_ // error in call to math.MultipleOf: division by zero
mul3: false
mul4: true
mul5: true
Expand Down
2 changes: 1 addition & 1 deletion pkg/net/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ t3: ["::%lo0", "80"]
t4: "example.com:80"
t5: "[2001:db8::1]:80"
t6: "192.30.4.2:80"
t7: _|_ // error in call to net.JoinHostPort: invalid host [192, 30, 4] (and 1 more errors)
t7: _|_ // error in call to net.JoinHostPort: invalid host [192, 30, 4]
t8: true
t9: _|_ // t9: invalid value "23.23.23.2333" (does not satisfy net.IPv4)
t10: true
Expand Down
2 changes: 1 addition & 1 deletion pkg/path/testdata/error.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ joinErr: cannot use "foo" as *"unix" | "windows" | "plan9" | "aix" | "android" |

Result:
joinOK: "a/b"
joinErr: _|_ // joinErr: cannot use "foo" as *"unix" | "windows" | "plan9" | "aix" | "android" | "darwin" | "dragonfly" | "freebsd" | "hurd" | "illumos" | "ios" | "js" | "linux" | "nacl" | "netbsd" | "openbsd" | "solaris" | "zos" in argument 2 to path.Join (and 3 more errors)
joinErr: _|_ // joinErr: cannot use "foo" as *"unix" | "windows" | "plan9" | "aix" | "android" | "darwin" | "dragonfly" | "freebsd" | "hurd" | "illumos" | "ios" | "js" | "linux" | "nacl" | "netbsd" | "openbsd" | "solaris" | "zos" in argument 2 to path.Join (and 1 more errors)

8 changes: 4 additions & 4 deletions pkg/regexp/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ t14: invalid value "invalid)" (does not satisfy regexp.Valid): error in call to

Result:
t1: "foo"
t2: _|_ // error in call to regexp.Find: no match (and 1 more errors)
t2: _|_ // error in call to regexp.Find: no match
t3: ["foo", "flo"]
t4: ["foo", "flo"]
t5: _|_ // error in call to regexp.FindAll: no match (and 1 more errors)
t5: _|_ // error in call to regexp.FindAll: no match
t6: ["flo", "l", "o"]
t7: [["flo", "l", "o"], ["foo", "o", "o"], ["fro", "r", "o"]]
t8: _|_ // error in call to regexp.FindAllSubmatch: no match (and 1 more errors)
t8: _|_ // error in call to regexp.FindAllSubmatch: no match
t9: {
A: "l"
B: "o"
Expand All @@ -52,7 +52,7 @@ t10: [{
t11: [{
A: ""
}]
t12: _|_ // error in call to regexp.FindAllNamedSubmatch: no match (and 1 more errors)
t12: _|_ // error in call to regexp.FindAllNamedSubmatch: no match
t13: "valid"
t14: _|_ // t14: invalid value "invalid)" (does not satisfy regexp.Valid): error in call to regexp.Valid: error parsing regexp: unexpected ): `invalid)`

4 changes: 2 additions & 2 deletions pkg/strconv/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ t4: cannot use 1.0 (type float) as int in argument 2 to strconv.FormatFloat:

Result:
t1: "40"
t2: _|_ // int 300 overflows byte in argument 1 in call to strconv.FormatFloat (and 1 more errors)
t3: _|_ // cannot use -1 (type int) as byte in argument 1 to strconv.FormatFloat (and 1 more errors)
t2: _|_ // int 300 overflows byte in argument 1 in call to strconv.FormatFloat
t3: _|_ // cannot use -1 (type int) as byte in argument 1 to strconv.FormatFloat
t4: _|_ // t4: cannot use 1.0 (type float) as int in argument 2 to strconv.FormatFloat
t5: "true"

2 changes: 1 addition & 1 deletion pkg/strings/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ t17: invalid value "hello" (does not satisfy strings.MinRunes(10)):

Result:
t1: "Hello World!"
t2: _|_ // t2: invalid type element 0 (int) of string list argument 0 (and 1 more errors)
t2: _|_ // t2: invalid type element 0 (int) of string list argument 0
t3: 97
t4: 'llo'
t5: "✓ H"
Expand Down

0 comments on commit 908614e

Please sign in to comment.