mirror of
https://github.com/logos-storage/questionable.git
synced 2026-01-03 06:13:09 +00:00
Fix: without statement with error works in nested calls
This commit is contained in:
parent
13c7ff7671
commit
f6363e19d3
@ -4,10 +4,15 @@ var captureEnabled {.global, compileTime.}: bool
|
||||
var errorVariable: ptr ref CatchableError
|
||||
|
||||
template captureBindError*(error: var ref CatchableError, expression): auto =
|
||||
static: captureEnabled = true
|
||||
let previousErrorVariable = errorVariable
|
||||
errorVariable = addr error
|
||||
|
||||
static: captureEnabled = true
|
||||
let evaluated = expression
|
||||
static: captureEnabled = false
|
||||
|
||||
errorVariable = previousErrorVariable
|
||||
|
||||
evaluated
|
||||
|
||||
func error[T](option: Option[T]): ref CatchableError =
|
||||
|
||||
@ -281,6 +281,19 @@ suite "result":
|
||||
check e2.msg == "error2"
|
||||
check e1.msg == "error1"
|
||||
|
||||
test "without statements with error work in nested calls":
|
||||
proc bar(): ?!int =
|
||||
without _ =? int.failure "error", err:
|
||||
return failure err.msg
|
||||
|
||||
proc foo() =
|
||||
without _ =? bar(), err:
|
||||
check err.msg == "error"
|
||||
return
|
||||
fail()
|
||||
|
||||
foo()
|
||||
|
||||
test "catch can be used to convert exceptions to results":
|
||||
check parseInt("42").catch == 42.success
|
||||
check parseInt("foo").catch.error of ValueError
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user