Skip to main content

Module condition

Module condition 

Source
Expand description

Structured error adapter for std::error::Error.

RCondition wraps any E: std::error::Error and preserves the full error chain (cause/source) when converting to an R error message.

§Usage

Use as the Err type in Result returns from #[miniextendr] functions:

use miniextendr_api::condition::RCondition;

#[miniextendr]
fn parse_config(path: &str) -> Result<i32, RCondition<std::io::Error>> {
    let content = std::fs::read_to_string(path).map_err(RCondition)?;
    Ok(content.len() as i32)
}

The R error message includes the full cause chain:

tryCatch(parse_config("/nonexistent"), error = function(e) e$message)
# "No such file or directory (os error 2)\n  caused by: ..."

Structs§

RCondition
Structured error wrapper that preserves the std::error::Error cause chain.