mirror of
https://github.com/logos-storage/questionable.git
synced 2026-01-02 13:53:11 +00:00
25 lines
636 B
Nim
25 lines
636 B
Nim
import std/options
|
|
|
|
var captureEnabled {.global, compileTime.}: bool
|
|
var errorVariable: ptr ref CatchableError
|
|
|
|
template captureBindError*(error: var ref CatchableError, expression): auto =
|
|
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 =
|
|
newException(ValueError, "Option is set to `none`")
|
|
|
|
template bindFailed*(expression) =
|
|
when captureEnabled:
|
|
mixin error
|
|
errorVariable[] = expression.error
|