diff --git a/NAMESPACE b/NAMESPACE index 90c1bfa..fcba66d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,5 @@ # Generated by roxygen2: do not edit by hand export("%!%") -export(slap) import(cli) import(rlang) diff --git a/R/slap.R b/R/slap.R index 822374c..b7fd8c6 100644 --- a/R/slap.R +++ b/R/slap.R @@ -24,13 +24,14 @@ #' @name slap #' @export `%!%` <- function(expr, message) { - message <- enexpr(message) - quo <- quo( withCallingHandlers( {{ expr }}, - error = function(.__slap__.) { - message <- !!message + error = function(err) { + message <- {{ message }} + if (is.function(message)) { + message <- message(err) + } error_call <- env$.__error_call__. if (is.null(error_call)) { @@ -40,7 +41,7 @@ error_call <- NULL } - cli::cli_abort(message, parent = .__slap__., call = error_call) + cli::cli_abort(message, parent = err, call = error_call) } ) ) @@ -48,8 +49,3 @@ env <- caller_env() eval_tidy(quo, env = env, data = list(env = env)) } - -#' @export -slap <- function(error_call = current_env()) { - get(".__slap__.", caller_env()) %||% cli_abort("{.fn slap()} can only be used on the rhs of a `%!%`.", call = error_call) -}