From df01042d6e074b923ef22be92ff270de71cc9589 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Sat, 12 Sep 2020 19:56:21 +0200 Subject: [PATCH] internal/core/compile: better error message for user-defined errors Fixes #321 Change-Id: I0a04fd56a132a98ae3f143e91c4c185052cee4d7 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7069 Reviewed-by: Marcel van Lohuizen Reviewed-by: CUE cueckoo --- cue/testdata/basicrewrite/000_errors.txtar | 24 +++++++++---------- cue/testdata/comprehensions/issue287.txtar | 4 ++-- cue/testdata/eval/errunifiy.txtar | 6 ++--- .../031_comparison_against_bottom.txtar | 14 +++++------ cue/types_test.go | 24 +++++++++---------- internal/core/compile/compile.go | 2 +- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/cue/testdata/basicrewrite/000_errors.txtar b/cue/testdata/basicrewrite/000_errors.txtar index 6229e79f0..94d0545ce 100644 --- a/cue/testdata/basicrewrite/000_errors.txtar +++ b/cue/testdata/basicrewrite/000_errors.txtar @@ -9,38 +9,38 @@ c: b.a == _|_ d: _|_ != b.a e: _|_ == _|_ -- out/def -- -a: _|_ // from source -b: _|_ // from source +a: _|_ // explicit error (_|_ literal) in source +b: _|_ // explicit error (_|_ literal) in source c: true d: false e: true -- out/legacy-debug -- -<0>{a: _|_(from source), b: _|_(from source), c: true, d: false, e: true} +<0>{a: _|_(explicit error (_|_ literal) in source), b: _|_(explicit error (_|_ literal) in source), c: true, d: false, e: true} -- out/compile -- --- in.cue { - a: (_|_(from source) & _|_(from source)) - b: (null & _|_(from source)) - c: (〈0;b〉.a == _|_(from source)) - d: (_|_(from source) != 〈0;b〉.a) - e: (_|_(from source) == _|_(from source)) + a: (_|_(explicit error (_|_ literal) in source) & _|_(explicit error (_|_ literal) in source)) + b: (null & _|_(explicit error (_|_ literal) in source)) + c: (〈0;b〉.a == _|_(explicit error (_|_ literal) in source)) + d: (_|_(explicit error (_|_ literal) in source) != 〈0;b〉.a) + e: (_|_(explicit error (_|_ literal) in source) == _|_(explicit error (_|_ literal) in source)) } -- out/eval -- Errors: -from source: +explicit error (_|_ literal) in source: ./in.cue:1:4 -from source: +explicit error (_|_ literal) in source: ./in.cue:2:11 Result: (_|_){ // [user] a: (_|_){ - // [user] from source: + // [user] explicit error (_|_ literal) in source: // ./in.cue:1:4 } b: (_|_){ - // [user] from source: + // [user] explicit error (_|_ literal) in source: // ./in.cue:2:11 } c: (bool){ true } diff --git a/cue/testdata/comprehensions/issue287.txtar b/cue/testdata/comprehensions/issue287.txtar index 243e4b7c2..47b883fa5 100644 --- a/cue/testdata/comprehensions/issue287.txtar +++ b/cue/testdata/comprehensions/issue287.txtar @@ -18,12 +18,12 @@ if #E["y"] != _|_ { -- out/compile -- --- in.cue { - if (〈0;#E〉["x"] != _|_(from source)) { + if (〈0;#E〉["x"] != _|_(explicit error (_|_ literal) in source)) { #E: { y: true } } - if (〈0;#E〉["y"] != _|_(from source)) { + if (〈0;#E〉["y"] != _|_(explicit error (_|_ literal) in source)) { z: true } #E: { diff --git a/cue/testdata/eval/errunifiy.txtar b/cue/testdata/eval/errunifiy.txtar index e7b694ffe..bcb09aaaf 100644 --- a/cue/testdata/eval/errunifiy.txtar +++ b/cue/testdata/eval/errunifiy.txtar @@ -9,7 +9,7 @@ b: "t" -- out/eval -- Errors: -from source: +explicit error (_|_ literal) in source: ./in.cue:4:4 Result: @@ -17,7 +17,7 @@ Result: // [user] a: (string){ "t" } b: (_|_){ - // [user] from source: + // [user] explicit error (_|_ literal) in source: // ./in.cue:4:4 } } @@ -26,6 +26,6 @@ Result: { a: or([]) a: "t" - b: _|_(from source) + b: _|_(explicit error (_|_ literal) in source) b: "t" } diff --git a/cue/testdata/fulleval/031_comparison_against_bottom.txtar b/cue/testdata/fulleval/031_comparison_against_bottom.txtar index c0cceeb85..01f11ebfa 100644 --- a/cue/testdata/fulleval/031_comparison_against_bottom.txtar +++ b/cue/testdata/fulleval/031_comparison_against_bottom.txtar @@ -32,27 +32,27 @@ i: false -- out/compile -- --- in.cue { - a: (_|_(from source) == _|_(from source)) + a: (_|_(explicit error (_|_ literal) in source) == _|_(explicit error (_|_ literal) in source)) b: ((〈0;err〉 == 1) & 2) - c: (〈0;err〉 == _|_(from source)) - d: (〈0;err〉 != _|_(from source)) + c: (〈0;err〉 == _|_(explicit error (_|_ literal) in source)) + d: (〈0;err〉 != _|_(explicit error (_|_ literal) in source)) e: ((〈0;err〉 != 1) & 3) f: (({ a: 1 } & { a: 2 - }) == _|_(from source)) + }) == _|_(explicit error (_|_ literal) in source)) g: (({ a: 1 } & { b: 2 - }) == _|_(from source)) - h: (_|_(from source) == ({ + }) == _|_(explicit error (_|_ literal) in source)) + h: (_|_(explicit error (_|_ literal) in source) == ({ a: 1 } & { a: 2 })) - i: (_|_(from source) == ({ + i: (_|_(explicit error (_|_ literal) in source) == ({ a: 1 } & { b: 2 diff --git a/cue/types_test.go b/cue/types_test.go index 97bd718c1..66850e2f1 100644 --- a/cue/types_test.go +++ b/cue/types_test.go @@ -269,8 +269,8 @@ func TestInt(t *testing.T) { notInt: true, }, { value: "_|_", - err: "from source", - errU: "from source", + err: "explicit error (_|_ literal) in source", + errU: "explicit error (_|_ literal) in source", notInt: true, }} for _, tc := range testCases { @@ -485,7 +485,7 @@ func TestError(t *testing.T) { err string }{{ value: `_|_`, - err: "from source", + err: "explicit error (_|_ literal) in source", }, { value: `"Hello world!"`, }, { @@ -506,7 +506,7 @@ func TestNull(t *testing.T) { err string }{{ value: `v: _|_`, - err: "from source", + err: "explicit error (_|_ literal) in source", }, { value: `v: "str"`, err: "cannot use value \"str\" (type string) as null", @@ -531,7 +531,7 @@ func TestBool(t *testing.T) { err string }{{ value: `_|_`, - err: "from source", + err: "explicit error (_|_ literal) in source", }, { value: `"str"`, err: "cannot use value \"str\" (type string) as bool", @@ -563,7 +563,7 @@ func TestList(t *testing.T) { err string }{{ value: `_|_`, - err: "from source", + err: "explicit error (_|_ literal) in source", }, { value: `"str"`, err: "cannot use value \"str\" (type string) as list", @@ -614,7 +614,7 @@ func TestFields(t *testing.T) { res: "{reg:4,}", }, { value: `_|_`, - err: "from source", + err: "explicit error (_|_ literal) in source", }, { value: `"str"`, err: "cannot use value \"str\" (type string) as struct", @@ -1324,7 +1324,7 @@ func TestDecode(t *testing.T) { err string }{{ value: `_|_`, - err: "from source", + err: "explicit error (_|_ literal) in source", }, { value: `"str"`, dst: new(string), @@ -1607,11 +1607,11 @@ func TestValueLookup(t *testing.T) { }{{ config: "_|_", path: strList(""), - str: "from source", + str: "explicit error (_|_ literal) in source", }, { config: "_|_", path: strList("a"), - str: "from source", + str: "explicit error (_|_ literal) in source", }, { config: config, path: strList(), @@ -2107,7 +2107,7 @@ func TestMarshalJSON(t *testing.T) { json: `null`, }, { value: `_|_`, - err: "from source", + err: "explicit error (_|_ literal) in source", }, { value: `(a.b) a: {}`, @@ -2272,7 +2272,7 @@ func TestWalk(t *testing.T) { out: `null`, }, { value: `_|_`, - out: "_|_(from source)", + out: "_|_(explicit error (_|_ literal) in source)", }, { value: `(a.b) a: {}`, diff --git a/internal/core/compile/compile.go b/internal/core/compile/compile.go index eab01fd54..2e7d40628 100644 --- a/internal/core/compile/compile.go +++ b/internal/core/compile/compile.go @@ -778,7 +778,7 @@ func (c *compiler) expr(expr ast.Expr) adt.Expr { return &adt.Bottom{ Src: n, Code: adt.UserError, - Err: errors.Newf(n.Pos(), "from source"), + Err: errors.Newf(n.Pos(), "explicit error (_|_ literal) in source"), } case *ast.BadExpr: