R/utils-error_handler.R

Defines functions error_handler

Documented in error_handler

#' Handle errors with custom error classes
#'
#' A utility function to handle errors with specific error classes and provide
#' appropriate error messages using the cli package.
#'
#' @param e The error object to handle
#' @param e_class The expected error class to check against
#'
#' @return No return value; either displays an error message via cli or stops
#'   execution with the original error
#'
#' @keywords internal
error_handler <- function(e, e_class) {
  if (inherits(e, e_class)) {
    cli::cli_alert_danger(e$message)
  } else {
    stop(e)
  }
}

Try the eyeris package in your browser

Any scripts or data that you put into this service are public.

eyeris documentation built on July 3, 2025, 9:08 a.m.