Fix BareExcept warnings

This commit is contained in:
Mark Spanbroek 2023-12-19 15:23:12 +01:00 committed by markspanbroek
parent 4a74d65e17
commit 43e7deb827
2 changed files with 13 additions and 5 deletions

View File

@ -0,0 +1,6 @@
template ignoreBareExceptWarning*(body) =
when defined(nimHasWarnBareExcept):
{.push warning[BareExcept]:off warning[UnreachableCode]:off.}
body
when defined(nimHasWarnBareExcept):
{.pop.}

View File

@ -7,6 +7,7 @@ import ./indexing
import ./operators
import ./without
import ./withoutresult
import ./private/bareexcept
include ./private/errorban
@ -109,12 +110,13 @@ proc option*[T,E](value: Result[T,E]): ?T =
## Converts a Result into an Option.
if value.isOk:
try: # workaround for erroneous exception tracking when T is a closure
value.unsafeGet.some
except Exception as exception:
raise newException(Defect, exception.msg, exception)
ignoreBareExceptWarning:
try: # workaround for erroneous exception tracking when T is a closure
return value.unsafeGet.some
except Exception as exception:
raise newException(Defect, exception.msg, exception)
else:
T.none
return T.none
template toOption*[T, E](value: Result[T, E]): ?T =
## Converts a Result into an Option.