Catch errors in Go binding for DH_Next(). Use the same approach we took with Hits_Next(): trap errors and capture them to a member variable, and expect the user to check that no errors occurred after iteration finishes.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/dd4328b3 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/dd4328b3 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/dd4328b3 Branch: refs/heads/master Commit: dd4328b3a0c528e6d168c1c241bc07253c2e2c4b Parents: dac0e2b Author: Marvin Humphrey <[email protected]> Authored: Mon Nov 16 15:35:54 2015 -0800 Committer: Marvin Humphrey <[email protected]> Committed: Fri Nov 20 16:43:38 2015 -0800 ---------------------------------------------------------------------- go/build.go | 3 +++ go/lucy/store.go | 21 +++++++++++++++++++++ go/lucy/store_test.go | 3 +++ 3 files changed, 27 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/dd4328b3/go/build.go ---------------------------------------------------------------------- diff --git a/go/build.go b/go/build.go index 6dff074..6c55250 100644 --- a/go/build.go +++ b/go/build.go @@ -350,6 +350,9 @@ func specClasses(parcel *cfc.Parcel) { dhBinding := cfc.NewGoClass(parcel, "Lucy::Store::DirHandle") dhBinding.SpecMethod("Close", "Close() error") + dhBinding.SpecMethod("Next", "next() bool") + dhBinding.SpecMethod("", "Error() error") + dhBinding.SetSuppressStruct(true) dhBinding.Register() lockBinding := cfc.NewGoClass(parcel, "Lucy::Store::Lock") http://git-wip-us.apache.org/repos/asf/lucy/blob/dd4328b3/go/lucy/store.go ---------------------------------------------------------------------- diff --git a/go/lucy/store.go b/go/lucy/store.go index 6fabd16..7af8229 100644 --- a/go/lucy/store.go +++ b/go/lucy/store.go @@ -39,6 +39,11 @@ import "fmt" import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish" +type DirHandleIMP struct { + clownfish.ObjIMP + err error +} + func (e *LockErrIMP) Error() string { self := ((*C.lucy_LockErr)(unsafe.Pointer(e.TOPTR()))) return clownfish.CFStringToGo(unsafe.Pointer(C.LUCY_LockErr_Get_Mess(self))) @@ -644,6 +649,22 @@ func OpenRAMFileHandle(path string, flags uint32, ramFile RAMFile) (fh RAMFileHa return fh, err } +func (dh *DirHandleIMP) Error() error { + return dh.err +} + +func (dh *DirHandleIMP) next() bool { + var retval bool + dh.err = clownfish.TrapErr(func() { + self := (*C.lucy_DirHandle)(clownfish.Unwrap(dh, "dh")) + retval = bool(C.LUCY_DH_Next(self)) + }) + if dh.err != nil { + return false + } + return retval +} + func (dh *DirHandleIMP) Close() error { return clownfish.TrapErr(func() { self := (*C.lucy_DirHandle)(clownfish.Unwrap(dh, "dh")) http://git-wip-us.apache.org/repos/asf/lucy/blob/dd4328b3/go/lucy/store_test.go ---------------------------------------------------------------------- diff --git a/go/lucy/store_test.go b/go/lucy/store_test.go index 69bb0d4..c422525 100644 --- a/go/lucy/store_test.go +++ b/go/lucy/store_test.go @@ -598,6 +598,9 @@ func runDirHandleCommonTests(t *testing.T, folder Folder, makeDH func() DirHandl t.Errorf("Unexpected entry: '%s'", entry) } } + if got := dh.Error(); got != nil { + t.Errorf("Error() should return nil after iteration: %v", got) + } if count != 2 { t.Errorf("Didn't get to all entries, found only %d", count) }
