Title: | Handle Error and Warning Messages |
---|---|
Description: | Elegantly handle error and warning messages. |
Authors: | John Coene [aut, cre], Opifex [cph] |
Maintainer: | John Coene <[email protected]> |
License: | AGPL-3 |
Version: | 2.2.0.9000 |
Built: | 2024-10-31 04:35:45 UTC |
Source: | https://github.com/devOpifex/erratum |
Equivalent to tryCatch()
.
bash(expr, e = NULL, w = NULL)
bash(expr, e = NULL, w = NULL)
expr |
Expression to run, passed to |
e , w
|
An object of class |
safe_log <- function(x){ result <- bash(log(x)) if(is.e(result)) stop(result$stop()) return(result) } if(interactive()) safe_log("a")
safe_log <- function(x){ result <- bash(log(x)) if(is.e(result)) stop(result$stop()) return(result) } if(interactive()) safe_log("a")
Check whether an object is an error or a warning.
is.e(obj) ## Default S3 method: is.e(obj) ## S3 method for class 'err' is.e(obj) is.w(obj) ## Default S3 method: is.w(obj) ## S3 method for class 'err' is.w(obj) is.problem(obj)
is.e(obj) ## Default S3 method: is.e(obj) ## S3 method for class 'err' is.e(obj) is.w(obj) ## Default S3 method: is.w(obj) ## S3 method for class 'err' is.w(obj) is.problem(obj)
obj |
Object to check. |
A boolean value.
is.e
: Whether the object is an error.
is.w
: Whether the object is a warning.
is.problem
: Whether the object is an error or a warning.
err <- e("Whoops!") is.e(err) is.w(err)
err <- e("Whoops!") is.e(err) is.w(err)
Observe with erratum error handling.
e.observe( x, e = NULL, w = NULL, env = parent.frame(), ..., label = NULL, suspended = FALSE, priority = 0, domain = shiny::getDefaultReactiveDomain(), autoDestroy = TRUE, ..stacktraceon = TRUE )
e.observe( x, e = NULL, w = NULL, env = parent.frame(), ..., label = NULL, suspended = FALSE, priority = 0, domain = shiny::getDefaultReactiveDomain(), autoDestroy = TRUE, ..stacktraceon = TRUE )
x |
An expression (quoted or unquoted). Any return value will be ignored. |
e |
Error handler. |
w |
Warning handler. |
env |
The parent environment for the reactive expression. By default,
this is the calling environment, the same as when defining an ordinary
non-reactive expression. If |
... |
Not used. |
label |
A label for the observer, useful for debugging. |
suspended |
If |
priority |
An integer or numeric that controls the priority with which this observer should be executed. A higher value means higher priority: an observer with a higher priority value will execute before all observers with lower priority values. Positive, negative, and zero values are allowed. |
domain |
See domains. |
autoDestroy |
If |
..stacktraceon |
Advanced use only. For stack manipulation purposes; see
|
Observe event with erratum error handling.
e.observe.event( eventExpr, handlerExpr, e = NULL, w = NULL, event.env = parent.frame(), event.quoted = FALSE, handler.env = parent.frame(), handler.quoted = FALSE, ..., label = NULL, suspended = FALSE, priority = 0, domain = shiny::getDefaultReactiveDomain(), autoDestroy = TRUE, ignoreNULL = TRUE, ignoreInit = FALSE, once = FALSE )
e.observe.event( eventExpr, handlerExpr, e = NULL, w = NULL, event.env = parent.frame(), event.quoted = FALSE, handler.env = parent.frame(), handler.quoted = FALSE, ..., label = NULL, suspended = FALSE, priority = 0, domain = shiny::getDefaultReactiveDomain(), autoDestroy = TRUE, ignoreNULL = TRUE, ignoreInit = FALSE, once = FALSE )
eventExpr |
A (quoted or unquoted) expression that represents the event;
this can be a simple reactive value like |
handlerExpr |
The expression to call whenever |
e |
Error handler. |
w |
Warning handler. |
event.env |
The parent environment for the reactive expression. By default,
this is the calling environment, the same as when defining an ordinary
non-reactive expression. If |
event.quoted |
If it is |
handler.env |
The parent environment for the reactive expression. By default,
this is the calling environment, the same as when defining an ordinary
non-reactive expression. If |
handler.quoted |
If it is |
... |
Currently not used. |
label |
A label for the observer or reactive, useful for debugging. |
suspended |
If |
priority |
An integer or numeric that controls the priority with which this observer should be executed. An observer with a given priority level will always execute sooner than all observers with a lower priority level. Positive, negative, and zero values are allowed. |
domain |
See domains. |
autoDestroy |
If |
ignoreNULL |
Whether the action should be triggered (or value
calculated, in the case of |
ignoreInit |
If |
once |
Whether this |
Error
Error
erratum::Issue
-> Error
new()
Error$new(obj, raiser = getOption("ERR_RAISER_ERROR", stopper))
obj
A character string or an object of
class error
, or warning
.
raiser
Template to raise the issue.
Initialise
stop()
Error$stop()
Stop
Analogous to stop()
fatal()
Error$fatal()
Fatal
Analogous to stop()
clone()
The objects of this class are cloneable with this method.
Error$clone(deep = FALSE)
deep
Whether to make a deep clone.
Handle errors and warnings.
e(obj) w(obj)
e(obj) w(obj)
obj |
A character string or an object of
class |
err <- e("Something went wrong") foo <- function(x){ if(is.character(x)) return(err) log(x) } foo("a")
err <- e("Something went wrong") foo <- function(x){ if(is.character(x)) return(err) log(x) } foo("a")
Extract call from error and warnings.
get_call(obj)
get_call(obj)
obj |
Message string, object of class |
Extract message from error and warnings.
get_msg(obj)
get_msg(obj)
obj |
Message string, object of class |
Core class to create and handle issues.
rule
Rules to perform checks, must be functions that accept a single argument and return a boolean.
message
The message (warning or error).
call
Expression or function (as string) that led to the issue.
raiser
Function to run when the raise
method
is called. By default the error uses stop()
and warning
uses warning()
. The function must accept a single argument:
the error message (character vector).
new()
Issue$new(obj, type = c("error", "warning"))
obj
A character string or an object of
class error
, or warning
.
type
Type of message.
Initialise
print()
Issue$print()
Print message of error or warning.
return()
Issue$return(n = 1)
n
the number of generations to go back, passed to
parent.frame()
.
Return Returns self from parent function.
addRule()
Issue$addRule(fn)
fn
Function defining rule, must accept a single argument and return a boolean.
Add a rule
check()
Issue$check(obj)
obj
Object to check by rules
Add a predicate
raise()
Issue$raise(fn = NULL)
fn
A function to use to raise the issue.
Raise error or warning
clone()
The objects of this class are cloneable with this method.
Issue$clone(deep = FALSE)
deep
Whether to make a deep clone.
Latch an error or a warning to an object
to indicate an issue associated with it.
These can later be checked with is.e()
and is.w()
, and can also be resolve()
.
latch.e(obj, error) latch.w(obj, warning) unlatch(obj)
latch.e(obj, error) latch.w(obj, warning) unlatch(obj)
obj |
Object to latch the error or warning onto. |
error , warning
|
latche
and latchw
: latch an error or a warning.
unlatch
: unlatch any error or warning.
x <- 1 problematic <- latch.e(x, e("Not right")) is.e(problematic) do_sth_with_x <- function(x){ resolve(x) x + 1 } if(interactive()){ do_sth_with_x(x) do_sth_with_x(problematic) } unlatch(problematic)
x <- 1 problematic <- latch.e(x, e("Not right")) is.e(problematic) do_sth_with_x <- function(x){ resolve(x) x + 1 } if(interactive()){ do_sth_with_x(x) do_sth_with_x(problematic) } unlatch(problematic)
Set raise
method globally, every subsequent raise
method will make use of this function.
raise.e(fn = NULL) raise.w(fn = NULL)
raise.e(fn = NULL) raise.w(fn = NULL)
fn |
Function to run when the |
Resolve Errors and Warnings
resolve(...) defer_resolve(...)
resolve(...) defer_resolve(...)
... |
Objects to check, if any of them is an |
Objects passed are evalutated in order.
Invisiby returns NULL
Skip the rest of the function; calls return()
in the
parent function if any object is an error or (optionally)
a warning.
skip(..., w = FALSE)
skip(..., w = FALSE)
... |
Objects to check, if any of them is an |
w |
Whether to also skip is there are |
Define error and warning templates.
template.e(pat = "%s") template.w(pat = "%s")
template.e(pat = "%s") template.w(pat = "%s")
pat |
Pattern to use, must include |
msg <- "Something's wrong" # default e(msg) # template template.e("Whoops: %s - sorry!") e(msg) # reset template.e()
msg <- "Something's wrong" # default e(msg) # template template.e("Whoops: %s - sorry!") e(msg) # reset template.e()
Error
Error
erratum::Issue
-> Warning
new()
Warning$new(obj, raiser = getOption("ERR_RAISER_WARNING", warner))
obj
A character string or an object of
class error
, or warning
.
raiser
Template to raise the issue.
Initialise
warn()
Warning$warn()
Warn
Analogous to warning()
clone()
The objects of this class are cloneable with this method.
Warning$clone(deep = FALSE)
deep
Whether to make a deep clone.