Skip to content

Commit

Permalink
cue/errors: don't equate error messages without line info
Browse files Browse the repository at this point in the history
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 <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Jul 3, 2020
1 parent 16a2b89 commit a20e1d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cmd/cue/cmd/testdata/script/eval_errs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ cmp stdout expect-stdout
bar: empty disjunction: conflicting values int and "str" (mismatched types int and string):
./errs.cue:5:10
./errs.cue:6:16
bar: empty disjunction: conflicting values string and 2 (mismatched types string and int):
./errs.cue:5:21
./errs.cue:6:26
x.q: conflicting values "hello" and "goodbye":
./errs.cue:1:4
./errs.cue:2:4
Expand Down
17 changes: 12 additions & 5 deletions cue/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,7 @@ func (p *list) RemoveMultiples() {
var last Error
i := 0
for _, e := range *p {
pos := e.Position()
if last == nil ||
pos.Filename() != last.Position().Filename() ||
pos.Line() != last.Position().Line() ||
!equalPath(e.Path(), last.Path()) {
if last == nil || !approximateEqual(last, e) {
last = e
(*p)[i] = e
i++
Expand All @@ -375,6 +371,17 @@ func (p *list) RemoveMultiples() {
(*p) = (*p)[0:i]
}

func approximateEqual(a, b Error) bool {
aPos := a.Position()
bPos := b.Position()
if aPos == token.NoPos || bPos == token.NoPos {
return a.Error() == b.Error()
}
return aPos.Filename() == bPos.Filename() &&
aPos.Line() == bPos.Line() &&
equalPath(a.Path(), b.Path())
}

// An List implements the error interface.
func (p list) Error() string {
format, args := p.Msg()
Expand Down
2 changes: 1 addition & 1 deletion cuego/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ExampleComplete_structTag() {
//Output:
// completed: cuego_test.Sum{A:1, B:5, C:6} (err: <nil>)
// completed: cuego_test.Sum{A:2, B:6, C:8} (err: <nil>)
// empty disjunction: conflicting values 5 and 2
// empty disjunction: conflicting values 5 and 2 (and 1 more errors)
}

func ExampleConstrain() {
Expand Down

0 comments on commit a20e1d4

Please sign in to comment.