mirror of
https://github.com/logos-storage/questionable.git
synced 2026-01-03 06:13:09 +00:00
Fix BareExcept warnings
This commit is contained in:
parent
1f0afff48b
commit
247ad04918
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 ./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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user