Skip to main content

ARG_ERROR_HELPER

Constant ARG_ERROR_HELPER 

Source
const ARG_ERROR_HELPER: &str = r#"# Internal helper: raise an argument error from an R-side check: a
# type / length precondition, `no_na`, `inherits`, or a `match_arg` /
# `choices` value. The condition is the one a failed Rust conversion raises:
# the crate's `conversion_error_class` (`.miniextendr_conversion_error_class`,
# at the end of this preamble), then `rust_error`, with
# `kind = "conversion"` and `e$param`, so one handler catches an argument
# error whichever side finds it. The message is `'<param>' <what>`, or the
# author's own `message` (`inherits(..., message = )` / `no_na(message = )`),
# used as given. `call` defaults to the wrapper's own call, as `stopifnot()`
# reported it; a `call = caller` wrapper passes `.mx_call`, by name
# next to a named `message`; an S3 method passes its frame, resolved here to
# the generic's call (`.miniextendr_frame_call`); a `call = none` wrapper
# passes NULL. Only a failing check calls this: the passing path is one
# `isTRUE()` test per check.
.miniextendr_arg_error <- function(param, what, call = sys.call(-1L), message = sprintf("'%s' %s", param, what)) {
  if (is.environment(call)) call <- .miniextendr_frame_call(call)
  stop(structure(
    list(message = message, call = call, kind = "conversion", param = param),
    class = c(.miniextendr_conversion_error_class, "rust_error", "simpleError", "error", "condition")
  ))
}
"#;