abort: Dual-channel error signal

View source: R/log.R

abortR Documentation

Dual-channel error signal

Description

Signals a condition AND optionally writes a styled event line to the operator console. The two channels carry complementary information so nothing is duplicated:

Usage

abort(
  ...,
  class = NULL,
  data = NULL,
  parent = NULL,
  verbosity = NULL,
  package = NULL
)

Arguments

...

Message components, concatenated with no separator.

class

Character vector: Additional condition classes (prepended to the base c("rtemis_error", "error", "condition")).

data

Named list or NULL: Structured fields attached to the signalled condition, retrievable by handlers via ⁠condition$<name>⁠ (e.g. data = list(status_code = 429L, provider = "anthropic")). Fields ride on the condition only - they are not echoed to the console or appended to the message. Names must not collide with the built-in condition fields message, parent, call, calls. trace is rejected too - not because abort() sets it, but because rlang and testthat read that field as an rlang::trace_back() object (see details).

parent

Condition or NULL: Wrapped parent condition. Its message is echoed to the console (when verbosity allows) and stored on the signalled condition as ⁠$parent⁠.

verbosity

Integer or NULL: Overrides get_verbosity() for the console echo. Set to 0L to suppress the echo without affecting the signalled condition.

package

Character or NULL: Package name for verbosity override.

Details

  • Console echo (when verbosity allows): the most-specific condition class plus the caller bracket - a structured "what failed, where" line. Falls back to "rtemis_error" when class = NULL so the line is always namespace-tagged and recognizable as ours.

  • Condition ⁠$message⁠: the corrective human-readable text passed via .... Plain text with all ANSI escapes stripped, so it is safe to serialize into JSON, HTML, or any other ANSI-unaware sink (e.g. browser-side error display), and is what conditionMessage() / R's default error printer / tryCatch(error = ...) handlers see.

Use class to add wire-protocol-specific condition classes that callers can catch via tryCatch(). The base classes "rtemis_error", "error", and "condition" are always added.

The condition also carries ⁠$calls⁠ - a pairlist of sys.calls() captured at the abort site, with abort()'s own frame trimmed. Unlike base R's traceback() (which only sees .Traceback, populated only when an error reaches the top-level uncaught), ⁠$calls⁠ survives tryCatch() and travels with the condition - so server-side handlers can ship the stack to a browser-side debug pane, or callers can call format_trace() to print it.

The field is deliberately not named trace: rlang and testthat treat that name as an rlang::trace_back() object and call nrow() on it, so a pairlist there makes testthat's reporter fail while formatting the error. Leaving the name unclaimed also lets testthat show its own backtrace, which is pruned to user frames where this one is not. For the same reason abort() rejects data$trace, so a caller cannot put the crash back by another route.

Value

Does not return - always signals a condition via stop().

Author(s)

EDG

Examples

## Not run: 
abort("Could not parse ", "hyperparameters", ".",
      class = "rtemislive_invalid_params")

## End(Not run)

rtemis.core documentation built on Sept. 20, 2026, 9:06 a.m.