From 57e2a702767b4f3171018ec8c3f9cbda74343261 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Tue, 26 Sep 2023 13:40:57 -0700 Subject: [PATCH] setup query --- datastore/threads/threadproxyds.nim | 3 +++ datastore/threads/threadresult.nim | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/datastore/threads/threadproxyds.nim b/datastore/threads/threadproxyds.nim index cf1960e..8ad8ba2 100644 --- a/datastore/threads/threadproxyds.nim +++ b/datastore/threads/threadproxyds.nim @@ -98,6 +98,9 @@ template executeTask[T](ctx: ptr TaskCtx[T], blk: untyped) = except CatchableError as exc: trace "Unexpected exception thrown in async task", exc = exc.msg ctx[].res.err exc.toThreadErr() + except Exception as exc: + trace "Unexpected defect thrown in async task", exc = exc.msg + ctx[].res.err exc.toThreadErr() finally: ctx.setDone() discard ctx[].signal.fireSync() diff --git a/datastore/threads/threadresult.nim b/datastore/threads/threadresult.nim index c0fb7ed..b1694f4 100644 --- a/datastore/threads/threadresult.nim +++ b/datastore/threads/threadresult.nim @@ -16,18 +16,20 @@ type DatastoreErr, DatastoreKeyNotFoundErr, QueryEndedErr, - CatchableErr + CatchableErr, + DefectErr ThreadTypes* = void | bool | SomeInteger | DataBuffer | tuple | Atomic ThreadResErr* = (ErrorEnum, DataBuffer) ThreadResult*[T: ThreadTypes] = Result[T, ThreadResErr] -converter toThreadErr*(e: ref CatchableError): ThreadResErr {.inline, raises: [].} = +converter toThreadErr*(e: ref Exception): ThreadResErr {.inline, raises: [].} = if e of DatastoreKeyNotFound: (ErrorEnum.DatastoreKeyNotFoundErr, DataBuffer.new(e.msg)) elif e of QueryEndedError: (ErrorEnum.QueryEndedErr, DataBuffer.new(e.msg)) elif e of DatastoreError: (DatastoreErr, DataBuffer.new(e.msg)) elif e of CatchableError: (CatchableErr, DataBuffer.new(e.msg)) + elif e of Defect: (DefectErr, DataBuffer.new(e.msg)) else: raise (ref Defect)(msg: e.msg) converter toExc*(e: ThreadResErr): ref CatchableError = @@ -36,3 +38,4 @@ converter toExc*(e: ThreadResErr): ref CatchableError = of ErrorEnum.QueryEndedErr: (ref QueryEndedError)(msg: $e[1]) of ErrorEnum.DatastoreErr: (ref DatastoreError)(msg: $e[1]) of ErrorEnum.CatchableErr: (ref CatchableError)(msg: $e[1]) + of ErrorEnum.DefectErr: (ref CatchableError)(msg: "defect: " & $e[1])