diff --git a/codex/errors.nim b/codex/errors.nim index ebb07f04..ff2789b9 100644 --- a/codex/errors.nim +++ b/codex/errors.nim @@ -7,6 +7,8 @@ ## This file may not be copied, modified, or distributed except according to ## those terms. +import std/options + import pkg/stew/results import pkg/chronos import pkg/questionable/results @@ -29,6 +31,12 @@ template mapFailure*[T, V, E]( template mapFailure*[T, V](exp: Result[T, V]): Result[T, ref CatchableError] = mapFailure(exp, CodexError) +template toResult*[T](exp: Option[T]): Result[T, ref CatchableError] = + if exp.isSome: + success exp.get + else: + T.failure("Option is None") + proc allFutureResult*[T](fut: seq[Future[T]]): Future[?!void] {.async.} = try: await allFuturesThrowing(fut)