mirror of
https://github.com/logos-storage/questionable.git
synced 2026-01-05 23:33:12 +00:00
Fix BareExcept warnings
This commit is contained in:
parent
4a74d65e17
commit
43e7deb827
6
questionable/private/bareexcept.nim
Normal file
6
questionable/private/bareexcept.nim
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
template ignoreBareExceptWarning*(body) =
|
||||||
|
when defined(nimHasWarnBareExcept):
|
||||||
|
{.push warning[BareExcept]:off warning[UnreachableCode]:off.}
|
||||||
|
body
|
||||||
|
when defined(nimHasWarnBareExcept):
|
||||||
|
{.pop.}
|
||||||
@ -7,6 +7,7 @@ import ./indexing
|
|||||||
import ./operators
|
import ./operators
|
||||||
import ./without
|
import ./without
|
||||||
import ./withoutresult
|
import ./withoutresult
|
||||||
|
import ./private/bareexcept
|
||||||
|
|
||||||
include ./private/errorban
|
include ./private/errorban
|
||||||
|
|
||||||
@ -109,12 +110,13 @@ proc option*[T,E](value: Result[T,E]): ?T =
|
|||||||
## Converts a Result into an Option.
|
## Converts a Result into an Option.
|
||||||
|
|
||||||
if value.isOk:
|
if value.isOk:
|
||||||
try: # workaround for erroneous exception tracking when T is a closure
|
ignoreBareExceptWarning:
|
||||||
value.unsafeGet.some
|
try: # workaround for erroneous exception tracking when T is a closure
|
||||||
except Exception as exception:
|
return value.unsafeGet.some
|
||||||
raise newException(Defect, exception.msg, exception)
|
except Exception as exception:
|
||||||
|
raise newException(Defect, exception.msg, exception)
|
||||||
else:
|
else:
|
||||||
T.none
|
return T.none
|
||||||
|
|
||||||
template toOption*[T, E](value: Result[T, E]): ?T =
|
template toOption*[T, E](value: Result[T, E]): ?T =
|
||||||
## Converts a Result into an Option.
|
## Converts a Result into an Option.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user