From 742277e72e4eb4b0ef7a04b27795ce2933adc657 Mon Sep 17 00:00:00 2001 From: Andrew Dunham Date: Tue, 14 Apr 2015 17:07:25 -0700 Subject: [PATCH] Fix Err fallout for graph/iterator.And iterator --- graph/iterator/and_iterator.go | 8 ++++++++ graph/iterator/and_iterator_test.go | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/graph/iterator/and_iterator.go b/graph/iterator/and_iterator.go index d8d45e5..0cd6cfb 100644 --- a/graph/iterator/and_iterator.go +++ b/graph/iterator/and_iterator.go @@ -29,6 +29,7 @@ type And struct { primaryIt graph.Iterator checkList []graph.Iterator result graph.Value + err error runstats graph.IteratorStats } @@ -153,9 +154,16 @@ func (it *And) Next() bool { return graph.NextLogOut(it, curr, true) } } + if err := graph.Err(it.primaryIt); err != nil { + it.err = err + } return graph.NextLogOut(it, nil, false) } +func (it *And) Err() error { + return it.err +} + func (it *And) Result() graph.Value { return it.result } diff --git a/graph/iterator/and_iterator_test.go b/graph/iterator/and_iterator_test.go index 3f96519..1bc2182 100644 --- a/graph/iterator/and_iterator_test.go +++ b/graph/iterator/and_iterator_test.go @@ -15,6 +15,7 @@ package iterator import ( + "errors" "testing" "github.com/google/cayley/graph" @@ -138,5 +139,20 @@ func TestAllIterators(t *testing.T) { if and.Next() { t.Error("Too many values") } - +} + +func TestAndIteratorErr(t *testing.T) { + retErr := errors.New("unique") + allErr := newTestIterator(false, retErr) + + and := NewAnd() + and.AddSubIterator(allErr) + and.AddSubIterator(NewInt64(1, 5)) + + if and.Next() != false { + t.Errorf("And iterator did not pass through initial 'false'") + } + if and.Err() != retErr { + t.Errorf("And iterator did not pass through underlying Err") + } }