Skip to content

Commit cc4c737

Browse files
authored
silence mass dump of BareExcept when using unittest (#25260)
Seems better to change it to `CatchableError` instead?
1 parent 92468e9 commit cc4c737

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

compiler/semstmts.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,9 @@ proc semTry(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil)
394394
elif a.len == 1:
395395
# count number of ``except: body`` blocks
396396
inc catchAllExcepts
397-
message(c.config, a.info, warnBareExcept,
398-
"The bare except clause is deprecated; use `except CatchableError:` instead")
397+
if noPanicOnExcept in c.graph.config.legacyFeatures:
398+
message(c.config, a.info, warnBareExcept,
399+
"The bare except clause is deprecated; use `except CatchableError:` instead")
399400
else:
400401
# support ``except KeyError, ValueError, ... : body``
401402
if catchAllExcepts > 0:

lib/pure/unittest.nim

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,11 @@ template test*(name, body) {.dirty.} =
547547
for formatter in formatters:
548548
formatter.testStarted(name)
549549

550-
{.push warning[BareExcept]:off.}
551550
try:
552551
when declared(testSetupIMPLFlag): testSetupIMPL()
553552
when declared(testTeardownIMPLFlag):
554553
defer: testTeardownIMPL()
555-
{.push warning[BareExcept]:on.}
556554
body
557-
{.pop.}
558555

559556
except Exception:
560557
let e = getCurrentException()
@@ -577,7 +574,6 @@ template test*(name, body) {.dirty.} =
577574
)
578575
testEnded(testResult)
579576
checkpoints = @[]
580-
{.pop.}
581577

582578
proc checkpoint*(msg: string) =
583579
## Set a checkpoint identified by `msg`. Upon test failure all
@@ -801,11 +797,8 @@ macro expect*(exceptions: varargs[typed], body: untyped): untyped =
801797
discard
802798

803799
template expectBody(errorTypes, lineInfoLit, body): NimNode {.dirty.} =
804-
{.push warning[BareExcept]:off.}
805800
try:
806-
{.push warning[BareExcept]:on.}
807801
body
808-
{.pop.}
809802
checkpoint(lineInfoLit & ": Expect Failed, no exception was thrown.")
810803
fail()
811804
except errorTypes:
@@ -814,8 +807,6 @@ macro expect*(exceptions: varargs[typed], body: untyped): untyped =
814807
let err = getCurrentException()
815808
checkpoint(lineInfoLit & ": Expect Failed, " & $err.name & " was thrown.")
816809
fail()
817-
{.pop.}
818-
819810
var errorTypes = newNimNode(nnkBracket)
820811
var hasException = false
821812
for exp in exceptions:

0 commit comments

Comments
 (0)