Skip to main content

RError

Struct RError 

Source
pub struct RError {
    message: String,
    class: Vec<String>,
    data: ConditionData,
    call: ConditionCall,
    argument_message: Option<String>,
}
Expand description

A ready-made classed error value for Result<T, RError> returns.

Carries a message, an optional class vector, structured fields and the call choice, and implements RConditionData. Any std::error::Error converts into it with ? / From (the message keeps the caused by: chain, like AsRError), after which the builder methods add the R-facing parts (RError::class, RError::data, RError::without_call):

ⓘ
use miniextendr_api::condition::RError;

#[miniextendr]
pub fn parse_port(s: &str) -> Result<i32, RError> {
    let port: i32 = s
        .parse()
        .map_err(|e| RError::from(e).class(["pkg_bad_port", "pkg_error"]).data("input", s))?;
    Ok(port)
}
e <- tryCatch(parse_port("x"), pkg_bad_port = function(e) e)
e$input          # "x"
class(e)[1:2]    # "pkg_bad_port" "pkg_error"

RError deliberately does not implement std::error::Error: that keeps the blanket From<E: Error> coherent. It does implement Display (the message), so it also works with #[miniextendr(unwrap_in_r)].

Fields§

§message: String§class: Vec<String>§data: ConditionData§call: ConditionCall§argument_message: Option<String>

Implementations§

Source§

impl RError

Source

pub fn new(message: impl Into<String>) -> Self

A classless error with message.

Source

pub fn without_call(self) -> Self

Raise the condition without a call: conditionCall(e) is NULL and the printed condition has no In f(...) : prefix, like R’s stop(..., call. = FALSE). For an error or warning about the data, not the call. Applies to Result returns and the defer_* functions; see ConditionCall.

Source

pub fn class(self, class: impl ConditionClass) -> Self

Append user classes (most specific first). Accepts one string or a vector, see ConditionClass.

Source

pub fn data(self, name: impl Into<String>, value: impl Into<RValue>) -> Self

Attach a structured field readable as e$<name>. Any value with an RValue From impl works. The name must not be message, call or kind; see RESERVED_CONDITION_FIELDS.

Source

pub fn argument_message(self, message: impl Into<String>) -> Self

The whole message of the argument error when this error refuses an argument, used as given instead of '<p>' must be <expected>: <message>; see RConditionData::argument_message. message stays the message everywhere else.

ⓘ
fn model_object(x: SEXP) -> Result<(), RError> {
    if x.inherits_class(c"data.frame") {
        return Err(RError::new("got a data frame")
            .argument_message("use model_from_df() for a data frame"));
    }
    Ok(())
}
Source

pub fn message_str(&self) -> &str

The message.

Source

pub fn argument_message_str(&self) -> Option<&str>

The whole argument-error message, if one was given (RError::argument_message).

Source

pub fn classes(&self) -> &[String]

The user classes, most specific first.

Source

pub fn fields(&self) -> &ConditionData

The structured fields as attached (unprefixed).

Trait Implementations§

Source§

impl Clone for RError

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E: Error> From<E> for RError

Source§

fn from(err: E) -> Self

Message = the error’s Display plus its source() chain, one caused by: line per link (same rendering as AsRError).

Source§

impl RConditionData for RError

Source§

fn message(&self) -> String

The condition message (conditionMessage(e)).
Source§

fn class(&self) -> Vec<String>

User classes, most specific first; empty for none.
Source§

fn data(&self) -> Option<ConditionData>

Structured fields spliced into the condition object (e$<name>).
Source§

fn call(&self) -> ConditionCall

Whether the condition reports a call. ConditionCall::None makes conditionCall() NULL, like R’s call. = FALSE, for a condition about the data rather than the call; the default keeps the call the transport captured. Honoured by defer_* and by Result returns; an argument-conversion error always keeps the call (see conversion_err_parts). #[condition(call = none)] on a derived type or variant overrides this.
Source§

fn argument_message(&self) -> Option<String>

The whole message when this error refuses an argument, or None. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ConsumingFallible for T
where T: Clone,

Source§

impl<E> ConversionArgMessageClassed for E
where E: RConditionData,

Source§

impl<E> ConversionErrClassed for E
where E: RConditionData,

Source§

fn __mx_conversion_parts(&self, _expected_known: bool) -> ErrParts

Source§

impl<E> ErrPartsClassed for E
where E: RConditionData,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> RClone for T
where T: Clone,

Source§

fn r_clone(&self) -> T

Create a deep copy of this value.
Source§

#[doc(hidden)]
unsafe extern "C" fn __RClone_r_clone_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RClone + IntoR,

Method shim for RClone::r_clone. Read more
Source§

impl<T> RDebug for T
where T: Debug,

Source§

fn debug_str(&self) -> String

Get a compact debug string representation.
Source§

fn debug_str_pretty(&self) -> String

Get a pretty-printed debug string with indentation.
Source§

#[doc(hidden)]
unsafe extern "C" fn __RDebug_debug_str_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RDebug,

Method shim for RDebug::debug_str. Read more
Source§

#[doc(hidden)]
unsafe extern "C" fn __RDebug_debug_str_pretty_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RDebug,

Method shim for RDebug::debug_str_pretty. Read more
Source§

impl<T> RDisplay for T
where T: Display,

Source§

fn as_r_string(&self) -> String

Convert to a user-friendly string.
Source§

#[doc(hidden)]
unsafe extern "C" fn __RDisplay_as_r_string_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RDisplay,

Method shim for RDisplay::as_r_string. Read more
Source§

impl<T> SizeHint for T
where T: ?Sized,

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 104 bytes