From 7bcc20b93f5adbd51e8153324992f7a9030215e7 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 21 Dec 2023 10:17:17 +0100 Subject: [PATCH] Fix BareExcept warnings when using stdlib unittest with chronos v4 --- asynctest/private/chronos/unittest/runasync.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/asynctest/private/chronos/unittest/runasync.nim b/asynctest/private/chronos/unittest/runasync.nim index 1306038..10bc1b8 100644 --- a/asynctest/private/chronos/unittest/runasync.nim +++ b/asynctest/private/chronos/unittest/runasync.nim @@ -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: