setup query

This commit is contained in:
Jaremy Creechley 2023-09-26 13:40:57 -07:00
parent 86ee5d912c
commit 57e2a70276
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 8 additions and 2 deletions

View File

@ -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()

View File

@ -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])