From 790bea147f8e769e6cff1dc38266b59b3576ebb2 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Mon, 28 Dec 2020 15:59:49 -0600 Subject: [PATCH] make view and fragment not found errors constant based on code review feedback --- executor.go | 3 ++- rrtx.go | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/executor.go b/executor.go index cb0f76a06..1910d42e8 100644 --- a/executor.go +++ b/executor.go @@ -1537,7 +1537,8 @@ func executeDistinctShardBSI(ctx context.Context, qcx *Qcx, idx *Index, fieldNam existsBitmap, err := tx.OffsetRange(index, fieldName, view, shard, ShardWidth*shard, ShardWidth*0, ShardWidth*1) if err != nil { - if _, ok := errors.Cause(err).(ViewOrFragmentNotFound); ok { + switch errors.Cause(err) { + case ViewNotFound, FragmentNotFound: return result, nil } return result, errors.Wrap(err, "getting exists bitmap") diff --git a/rrtx.go b/rrtx.go index 0b4d7d1e7..6113067c4 100644 --- a/rrtx.go +++ b/rrtx.go @@ -373,13 +373,13 @@ func (tx *RoaringTx) getFragment(index, field, view string, shard uint64) (*frag v := f.view(view) if v == nil { - return nil, ViewOrFragmentNotFound(errors.Errorf("view not found: %q", view)) + return nil, errors.Wrapf(ViewNotFound, "getting %s", view) } frag := v.Fragment(shard) if frag == nil { - return nil, ViewOrFragmentNotFound(errors.Errorf("fragment not found: %q / %q / %d", field, view, shard)) + return nil, errors.Wrapf(FragmentNotFound, "field:%q, view:%q, shard:%d", field, view, shard) } // Note: we cannot cache frag into tx.fragment. @@ -389,7 +389,8 @@ func (tx *RoaringTx) getFragment(index, field, view string, shard uint64) (*frag return frag, nil } -type ViewOrFragmentNotFound error +const ViewNotFound = Error("view not found") +const FragmentNotFound = Error("fragment not found") func (tx *RoaringTx) bitmap(index, field, view string, shard uint64) (*roaring.Bitmap, error) { frag, err := tx.getFragment(index, field, view, shard)