Skip to content

Commit

Permalink
Fix BareExcept warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
markspanbroek committed Jan 9, 2024
1 parent 4a74d65 commit 43e7deb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions questionable/private/bareexcept.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
template ignoreBareExceptWarning*(body) =
when defined(nimHasWarnBareExcept):
{.push warning[BareExcept]:off warning[UnreachableCode]:off.}
body
when defined(nimHasWarnBareExcept):
{.pop.}
12 changes: 7 additions & 5 deletions questionable/results.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ./indexing
import ./operators
import ./without
import ./withoutresult
import ./private/bareexcept

include ./private/errorban

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 43e7deb

Please sign in to comment.