mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-02-19 21:23:09 +00:00
setup query
This commit is contained in:
parent
86ee5d912c
commit
57e2a70276
@ -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()
|
||||
|
||||
@ -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])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user