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
impl RError
Sourcepub fn without_call(self) -> Self
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.
Sourcepub fn class(self, class: impl ConditionClass) -> Self
pub fn class(self, class: impl ConditionClass) -> Self
Append user classes (most specific first). Accepts one string or a
vector, see ConditionClass.
Sourcepub fn data(self, name: impl Into<String>, value: impl Into<RValue>) -> Self
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.
Sourcepub fn argument_message(self, message: impl Into<String>) -> Self
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(())
}Sourcepub fn message_str(&self) -> &str
pub fn message_str(&self) -> &str
The message.
Sourcepub fn argument_message_str(&self) -> Option<&str>
pub fn argument_message_str(&self) -> Option<&str>
The whole argument-error message, if one was given
(RError::argument_message).
Sourcepub fn fields(&self) -> &ConditionData
pub fn fields(&self) -> &ConditionData
The structured fields as attached (unprefixed).
Trait Implementations§
Source§impl RConditionData for RError
impl RConditionData for RError
Source§fn data(&self) -> Option<ConditionData>
fn data(&self) -> Option<ConditionData>
e$<name>).Source§fn call(&self) -> ConditionCall
fn call(&self) -> ConditionCall
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.Auto Trait Implementations§
impl Freeze for RError
impl RefUnwindSafe for RError
impl Send for RError
impl Sync for RError
impl Unpin for RError
impl UnsafeUnpin for RError
impl UnwindSafe for RError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConsumingFallible for Twhere
T: Clone,
Source§impl<E> ConversionArgMessageClassed for Ewhere
E: RConditionData,
impl<E> ConversionArgMessageClassed for Ewhere
E: RConditionData,
Source§impl<E> ConversionErrClassed for Ewhere
E: RConditionData,
impl<E> ConversionErrClassed for Ewhere
E: RConditionData,
fn __mx_conversion_parts(&self, _expected_known: bool) -> ErrParts
Source§impl<E> ErrPartsClassed for Ewhere
E: RConditionData,
impl<E> ErrPartsClassed for Ewhere
E: RConditionData,
fn __mx_classed_parts(&self) -> Option<ErrParts>
Source§impl<T> RDebug for Twhere
T: Debug,
impl<T> RDebug for Twhere
T: Debug,
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
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