Fix BareExcept warnings when using stdlib unittest with chronos v4

This commit is contained in:
Mark Spanbroek 2023-12-21 10:17:17 +01:00 committed by markspanbroek
parent 90c1b35b67
commit 4f89a82a49
1 changed files with 8 additions and 1 deletions

View File

@ -4,7 +4,14 @@ import pkg/chronos/config
when compiles(config.chronosHandleException): # detect chronos v4
template runAsync*(body): untyped =
let asyncProc = proc {.async: (raises: [Exception]).} = body
# The unittest module from stdlib can still raise a bare Exception,
# so we allow chronos to convert it to an AsyncExceptionError, and
# we disable the ensuing BareExcept warning.
{.push warning[BareExcept]:off.}
let asyncProc =
proc {.async: (handleException: true, raises: [AsyncExceptionError]).} =
body
{.pop.}
waitFor asyncProc()
else: