cue: improved error messages
Issue #52.
Change-Id: I4a019ebb354df1fd0b0d026ce76a9bd0f14f7fd0
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2170
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
diff --git a/cue/binop.go b/cue/binop.go
index 663bd68..c2e8787 100644
--- a/cue/binop.go
+++ b/cue/binop.go
@@ -222,7 +222,7 @@
return other
}
src = mkBin(ctx, src.Pos(), op, x, other)
- return ctx.mkErr(src, "binary operation on non-ground top value")
+ return ctx.mkErr(src, codeIncomplete, "binary operation on (incomplete) top value")
}
func (x *basicType) binOp(ctx *context, src source, op op, other evaluated) evaluated {
@@ -681,7 +681,7 @@
switch op {
case opUnify:
if x.b != y.b {
- return ctx.mkErr(x, "failed to unify: %v != %v", x.b, y.b)
+ return ctx.mkErr(x, "conflicting values: %v != %v", x.b, y.b)
}
return x
case opLand:
@@ -711,7 +711,7 @@
str := other.strValue()
if x.str != str {
src := mkBin(ctx, src.Pos(), op, x, other)
- return ctx.mkErr(src, "failed to unify: %v != %v", x.str, str)
+ return ctx.mkErr(src, "conflicting values: %v != %v", x.str, str)
}
return x
case opLss, opLeq, opEql, opNeq, opGeq, opGtr:
@@ -754,7 +754,7 @@
switch op {
case opUnify:
if !bytes.Equal(x.b, b) {
- return ctx.mkErr(x, "failed to unify: %v != %v", x.b, b)
+ return ctx.mkErr(x, "conflicting values: %v != %v", x.b, b)
}
return x
case opLss, opLeq, opEql, opNeq, opGeq, opGtr:
@@ -863,7 +863,7 @@
case opUnify:
if x.v.Cmp(&y.v) != 0 {
src = mkBin(ctx, src.Pos(), op, x, other)
- return ctx.mkErr(src, "cannot unify numbers %v and %v", x.strValue(), y.strValue())
+ return ctx.mkErr(src, "conflicting values: %v != %v", x.strValue(), y.strValue())
}
if k != x.k {
n.v = x.v
@@ -1126,7 +1126,7 @@
n, m := len(x.params.arcs), len(y.params.arcs)
if n != m {
src = mkBin(ctx, src.Pos(), op, x, other)
- return ctx.mkErr(src, "number of params of params should match in unification (%d != %d)", n, m)
+ return ctx.mkErr(src, "number of params should match (%d != %d)", n, m)
}
arcs := make([]arc, len(x.arcs))
lambda := &lambdaExpr{binSrc(src.Pos(), op, x, other), ¶ms{arcs}, nil}
diff --git a/cue/resolve_test.go b/cue/resolve_test.go
index e645a6a..605b486 100644
--- a/cue/resolve_test.go
+++ b/cue/resolve_test.go
@@ -247,7 +247,7 @@
e: true
e: !true
`,
- out: "<0>{t: true, f: false, e: _|_(true:failed to unify: true != false)}",
+ out: "<0>{t: true, f: false, e: _|_(true:conflicting values: true != false)}",
}, {
desc: "boolean arithmetic",
in: `
@@ -258,7 +258,7 @@
e: true & true
f: true & false
`,
- out: "<0>{a: true, b: true, c: false, d: true, e: true, f: _|_(true:failed to unify: true != false)}",
+ out: "<0>{a: true, b: true, c: false, d: true, e: true, f: _|_(true:conflicting values: true != false)}",
}, {
desc: "basic type",
in: `
@@ -520,9 +520,9 @@
x: x + 1
`,
out: `<0>{` +
- `a: _|_((210 & 200):cannot unify numbers 210 and 200), ` +
- `b: _|_((210 & 200):cannot unify numbers 210 and 200), ` +
- `x: _|_((100 & 101):cannot unify numbers 100 and 101)}`,
+ `a: _|_((210 & 200):conflicting values: 210 != 200), ` +
+ `b: _|_((210 & 200):conflicting values: 210 != 200), ` +
+ `x: _|_((100 & 101):conflicting values: 100 != 101)}`,
// TODO: find a way to mark error in data.
}}
rewriteHelper(t, testCases, evalPartial)
@@ -877,7 +877,7 @@
`i2: 3, ` +
`t0: [<3>{a: 8}], ` +
`t1: [, ...int], ` +
- `e0: _|_(([<4>{},<4>{}] & [<5>{}]):incompatible list lengths: cannot unify numbers 2 and 1), ` +
+ `e0: _|_(([<4>{},<4>{}] & [<5>{}]):incompatible list lengths: conflicting values: 2 != 1), ` +
`e1: _|_(([, ...int] & [, ...float]):incompatible list types: unsupported op &(int, float): )` +
`}`,
}, {
@@ -1355,7 +1355,7 @@
`a3: <3>{a: _|_((=~"oo" & "bar"):"bar" does not match =~"oo"), b: =~"oo", c: =~"fo"}, ` +
`o1: <4>{a: string, b: string, c: "bar"}, ` +
`o2: <5>{a: "foo", b: string, c: "bar"}, ` +
- `o3: <6>{a: _|_((builtin:or ([<7>.b,<7>.c]) & "foo"):empty disjunction: failed to unify: baz != foo), b: "baz", c: "bar"}}`,
+ `o3: <6>{a: _|_((builtin:or ([<7>.b,<7>.c]) & "foo"):empty disjunction: conflicting values: baz != foo), b: "baz", c: "bar"}}`,
}, {
desc: "self-reference cycles conflicts with strings",
in: `
@@ -1365,7 +1365,7 @@
}
a x: "hey"
`,
- out: `<0>{a: <1>{x: _|_(("hey!?" & "hey"):failed to unify: hey!? != hey), y: "hey!"}}`,
+ out: `<0>{a: <1>{x: _|_(("hey!?" & "hey"):conflicting values: hey!? != hey), y: "hey!"}}`,
}, {
desc: "resolved self-reference cycles with disjunctions",
in: `
@@ -1463,11 +1463,11 @@
`xd5: 10, ` +
`xd3: 6, ` +
- `xe1: _|_((6 & 7):cannot unify numbers 6 and 7), ` +
- `xe2: _|_((6 & 7):cannot unify numbers 6 and 7), ` +
- `xe4: _|_((6 & 7):cannot unify numbers 6 and 7), ` +
- `xe5: _|_((6 & 7):cannot unify numbers 6 and 7), ` +
- `xe3: _|_((6 & 7):cannot unify numbers 6 and 7), ` +
+ `xe1: _|_((6 & 7):conflicting values: 6 != 7), ` +
+ `xe2: _|_((6 & 7):conflicting values: 6 != 7), ` +
+ `xe4: _|_((6 & 7):conflicting values: 6 != 7), ` +
+ `xe5: _|_((6 & 7):conflicting values: 6 != 7), ` +
+ `xe3: _|_((6 & 7):conflicting values: 6 != 7), ` +
`xf1: 8, ` +
`xf2: 8, ` +
@@ -1553,11 +1553,11 @@
`xd5: 10, ` +
`xd3: 6, ` +
- `xe1: _|_((6 & 7):cannot unify numbers 6 and 7), ` +
- `xe2: _|_((6 & 7):cannot unify numbers 6 and 7), ` +
- `xe4: _|_((6 & 7):cannot unify numbers 6 and 7), ` +
- `xe5: _|_((6 & 7):cannot unify numbers 6 and 7), ` +
- `xe3: _|_((6 & 7):cannot unify numbers 6 and 7), ` +
+ `xe1: _|_((6 & 7):conflicting values: 6 != 7), ` +
+ `xe2: _|_((6 & 7):conflicting values: 6 != 7), ` +
+ `xe4: _|_((6 & 7):conflicting values: 6 != 7), ` +
+ `xe5: _|_((6 & 7):conflicting values: 6 != 7), ` +
+ `xe3: _|_((6 & 7):conflicting values: 6 != 7), ` +
`z1: (*11 | 13), ` + // 13 is eliminated with evalFull
`z2: 10, ` +