diff --git a/iter-iter.go b/iter-iter.go index 8b343ee..6f6bd86 100644 --- a/iter-iter.go +++ b/iter-iter.go @@ -12,6 +12,8 @@ import ( "git.portale-stac.it/go-pkg/expr/scan" ) +const iterIterType = "IterIter" + type IterIter struct { it kern.Iterator count int64 @@ -22,7 +24,13 @@ type IterIter struct { } func NewIterIter(it kern.Iterator, ctx kern.ExprContext, exprs []*scan.Term) (iter kern.Iterator, err error) { - iter = &IterIter{it: it, count: 0, index: -1, ctx: ctx, exprList: exprs, current: nil} + if ctx == nil { + err = fmt.Errorf("context is required for %s", iterIterType) + } else if it == nil { + err = fmt.Errorf("source iterator is required for %s", iterIterType) + } else { + iter = &IterIter{it: it, count: 0, index: -1, ctx: ctx, exprList: exprs, current: nil} + } return } @@ -31,7 +39,7 @@ func (it *IterIter) String() string { } func (it *IterIter) TypeName() string { - return "IterIter" + return iterIterType } func (it *IterIter) HasOperation(name string) bool { diff --git a/t_iter-list_test.go b/t_iter-list_test.go index 6c35417..24ea2dc 100644 --- a/t_iter-list_test.go +++ b/t_iter-list_test.go @@ -92,9 +92,10 @@ func TestNewIterList5(t *testing.T) { } func TestNewIterList6(t *testing.T) { + ctx := NewSimpleStore() list := kern.NewListA("a", "b", "c", "d") - it1, _ := NewIterator(nil, list, nil) - it, _ := NewIterator(nil, it1, nil) + it1, _ := NewIterator(ctx, list, nil) + it, _ := NewIterator(ctx, it1, nil) if item, err := it.Next(); err != nil { t.Errorf("error: %v", err) } else if item != "a" {