Skip to content

Commit a20e1d4

Browse files
committed
cue/errors: don't equate error messages without line info
Previously, if two messages had no line and path information, the two were equated and one was erased. Not it falls back to the error message. Change-Id: I9dff793777c2384939dac0873729dc77981d165a Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6482 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent 16a2b89 commit a20e1d4

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

cmd/cue/cmd/testdata/script/eval_errs.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ cmp stdout expect-stdout
77
bar: empty disjunction: conflicting values int and "str" (mismatched types int and string):
88
./errs.cue:5:10
99
./errs.cue:6:16
10+
bar: empty disjunction: conflicting values string and 2 (mismatched types string and int):
11+
./errs.cue:5:21
12+
./errs.cue:6:26
1013
x.q: conflicting values "hello" and "goodbye":
1114
./errs.cue:1:4
1215
./errs.cue:2:4

cue/errors/errors.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,7 @@ func (p *list) RemoveMultiples() {
362362
var last Error
363363
i := 0
364364
for _, e := range *p {
365-
pos := e.Position()
366-
if last == nil ||
367-
pos.Filename() != last.Position().Filename() ||
368-
pos.Line() != last.Position().Line() ||
369-
!equalPath(e.Path(), last.Path()) {
365+
if last == nil || !approximateEqual(last, e) {
370366
last = e
371367
(*p)[i] = e
372368
i++
@@ -375,6 +371,17 @@ func (p *list) RemoveMultiples() {
375371
(*p) = (*p)[0:i]
376372
}
377373

374+
func approximateEqual(a, b Error) bool {
375+
aPos := a.Position()
376+
bPos := b.Position()
377+
if aPos == token.NoPos || bPos == token.NoPos {
378+
return a.Error() == b.Error()
379+
}
380+
return aPos.Filename() == bPos.Filename() &&
381+
aPos.Line() == bPos.Line() &&
382+
equalPath(a.Path(), b.Path())
383+
}
384+
378385
// An List implements the error interface.
379386
func (p list) Error() string {
380387
format, args := p.Msg()

cuego/examples_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func ExampleComplete_structTag() {
4242
//Output:
4343
// completed: cuego_test.Sum{A:1, B:5, C:6} (err: <nil>)
4444
// completed: cuego_test.Sum{A:2, B:6, C:8} (err: <nil>)
45-
// empty disjunction: conflicting values 5 and 2
45+
// empty disjunction: conflicting values 5 and 2 (and 1 more errors)
4646
}
4747

4848
func ExampleConstrain() {

0 commit comments

Comments
 (0)