From c75c85cbf85cb0ea7565faff7c49cf77d7c31ea1 Mon Sep 17 00:00:00 2001 From: Ryan McConnell Date: Mon, 10 Nov 2025 01:27:50 -0500 Subject: [PATCH] silence mass dump of `BareExcept` when using `unittest` (#25260) Seems better to change it to `CatchableError` instead? (cherry picked from commit cc4c7377b296f59c8183b246cb51bd025aac48e4) --- compiler/semstmts.nim | 5 +++-- lib/pure/unittest.nim | 9 --------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 09c287e0bc..3146d8efbc 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -394,8 +394,9 @@ proc semTry(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil) elif a.len == 1: # count number of ``except: body`` blocks inc catchAllExcepts - message(c.config, a.info, warnBareExcept, - "The bare except clause is deprecated; use `except CatchableError:` instead") + if noPanicOnExcept in c.graph.config.legacyFeatures: + message(c.config, a.info, warnBareExcept, + "The bare except clause is deprecated; use `except CatchableError:` instead") else: # support ``except KeyError, ValueError, ... : body`` if catchAllExcepts > 0: diff --git a/lib/pure/unittest.nim b/lib/pure/unittest.nim index 317cfbade2..2a3afdb056 100644 --- a/lib/pure/unittest.nim +++ b/lib/pure/unittest.nim @@ -547,14 +547,11 @@ template test*(name, body) {.dirty.} = for formatter in formatters: formatter.testStarted(name) - {.push warning[BareExcept]:off.} try: when declared(testSetupIMPLFlag): testSetupIMPL() when declared(testTeardownIMPLFlag): defer: testTeardownIMPL() - {.push warning[BareExcept]:on.} body - {.pop.} except Exception: let e = getCurrentException() @@ -577,7 +574,6 @@ template test*(name, body) {.dirty.} = ) testEnded(testResult) checkpoints = @[] - {.pop.} proc checkpoint*(msg: string) = ## Set a checkpoint identified by `msg`. Upon test failure all @@ -803,11 +799,8 @@ macro expect*(exceptions: varargs[typed], body: untyped): untyped = discard template expectBody(errorTypes, lineInfoLit, body): NimNode {.dirty.} = - {.push warning[BareExcept]:off.} try: - {.push warning[BareExcept]:on.} body - {.pop.} checkpoint(lineInfoLit & ": Expect Failed, no exception was thrown.") fail() except errorTypes: @@ -816,8 +809,6 @@ macro expect*(exceptions: varargs[typed], body: untyped): untyped = let err = getCurrentException() checkpoint(lineInfoLit & ": Expect Failed, " & $err.name & " was thrown.") fail() - {.pop.} - var errorTypes = newNimNode(nnkBracket) var hasException = false for exp in exceptions: