A convenience function to extract the error message attached to an object. A
method is implemented for validated_reactive_val()
objects.
Value
If the object contains an error message, an object with class
captured-error
if capture
is TRUE
or the error condition if capture
is FALSE
. Depending on your purpose, you may need to signalCondition()
or rlang::cnd_signal()
to actually signal the error. If the object does
not contain an error, NULL
.
Examples
vrv <- validated_reactive_val(
value = "good",
default = "default",
validation_expr = {
if (.vrv() == "bad") {
rlang::abort("is bad", class = "special_error")
}
.vrv()
}
)
shiny::isolate(extract_error(vrv))
#> NULL
vrv("bad")
shiny::isolate(vrv())
#> [1] "default"
captured_error <- shiny::isolate(extract_error(vrv))
class(captured_error)
#> [1] "captured-special_error" "captured-rlang_error" "captured-error"
#> [4] "captured-condition"
captured_error$message
#> [1] "is bad"
raw_error <- shiny::isolate(extract_error(vrv, capture = FALSE))
try(rlang::cnd_signal(raw_error))
#> Error : is bad