Skip to content

Commit 99e7b6d

Browse files
committed
cue: preserve path info in unification errors
We can do so by using Validate instead of the validate used for disjunctions. Change-Id: I96803f22263890ddec6694ffa278fdf19177d37e Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2561 Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent 1233594 commit 99e7b6d

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
unsupported op &(int, string):
1+
text:unsupported op &(int, string):
22
./testdata/tasks/task_tool.cue:29:9
33
tool/cli:4:9

cue/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func (e *valueError) Msg() (string, []interface{}) {
8282
}
8383

8484
func (e *valueError) Path() (a []string) {
85+
if e.v.path == nil {
86+
return nil
87+
}
8588
a, _ = e.v.path.appendPath(a, e.v.idx)
8689
return a
8790
}

cue/types.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,10 +1147,21 @@ func (v Value) Unify(w Value) Value {
11471147
b := w.path.v
11481148
src := binSrc(token.NoPos, opUnify, a, b)
11491149
val := mkBin(ctx, src.Pos(), opUnify, a, b)
1150-
if err := validate(ctx, val.evalPartial(ctx)); err != nil {
1151-
val = err
1150+
u := newValueRoot(ctx, val)
1151+
if err := u.Validate(); err != nil {
1152+
// TODO: record all errors in a Value.
1153+
switch x := errors.Errors(err)[0].(type) {
1154+
case *valueError:
1155+
p := *x.v.path
1156+
p.v = x.err
1157+
p.cache = x.err
1158+
u = Value{x.v.idx, &p}
1159+
1160+
default:
1161+
u = newValueRoot(ctx, ctx.mkErr(src, err))
1162+
}
11521163
}
1153-
return newValueRoot(ctx, val)
1164+
return u
11541165
}
11551166

11561167
// Format prints a debug version of a value.

0 commit comments

Comments
 (0)