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 <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
diff --git a/cue/testdata/basicrewrite/000_errors.txtar b/cue/testdata/basicrewrite/000_errors.txtar
index 6229e79..94d0545 100644
--- a/cue/testdata/basicrewrite/000_errors.txtar
+++ b/cue/testdata/basicrewrite/000_errors.txtar
@@ -9,38 +9,38 @@
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 243e4b7..47b883f 100644
--- a/cue/testdata/comprehensions/issue287.txtar
+++ b/cue/testdata/comprehensions/issue287.txtar
@@ -18,12 +18,12 @@
-- 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 e7b694f..bcb09aa 100644
--- a/cue/testdata/eval/errunifiy.txtar
+++ b/cue/testdata/eval/errunifiy.txtar
@@ -9,7 +9,7 @@
-- out/eval --
Errors:
-from source:
+explicit error (_|_ literal) in source:
./in.cue:4:4
Result:
@@ -17,7 +17,7 @@
// [user]
a: (string){ "t" }
b: (_|_){
- // [user] from source:
+ // [user] explicit error (_|_ literal) in source:
// ./in.cue:4:4
}
}
@@ -26,6 +26,6 @@
{
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 c0cceeb..01f11eb 100644
--- a/cue/testdata/fulleval/031_comparison_against_bottom.txtar
+++ b/cue/testdata/fulleval/031_comparison_against_bottom.txtar
@@ -32,27 +32,27 @@
-- 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 97bd718..66850e2 100644
--- a/cue/types_test.go
+++ b/cue/types_test.go
@@ -269,8 +269,8 @@
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 @@
err string
}{{
value: `_|_`,
- err: "from source",
+ err: "explicit error (_|_ literal) in source",
}, {
value: `"Hello world!"`,
}, {
@@ -506,7 +506,7 @@
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 @@
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 @@
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 @@
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 @@
err string
}{{
value: `_|_`,
- err: "from source",
+ err: "explicit error (_|_ literal) in source",
}, {
value: `"str"`,
dst: new(string),
@@ -1607,11 +1607,11 @@
}{{
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 @@
json: `null`,
}, {
value: `_|_`,
- err: "from source",
+ err: "explicit error (_|_ literal) in source",
}, {
value: `(a.b)
a: {}`,
@@ -2272,7 +2272,7 @@
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 eab01fd..2e7d406 100644
--- a/internal/core/compile/compile.go
+++ b/internal/core/compile/compile.go
@@ -778,7 +778,7 @@
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: