pub enum SexpError {
Type(SexpTypeError),
Class(SexpClassError),
Length(SexpLengthError),
Na(SexpNaError),
InvalidValue(String),
MissingField(String),
DuplicateName(String),
MatchArg(MatchArgError),
Condition(RError),
}Expand description
Unified conversion error when decoding an R SEXP.
Variants§
Type(SexpTypeError)
SEXPTYPE did not match the expected one.
Class(SexpClassError)
The value is not the kind of R object this conversion reads, where
that kind is a class (a data frame is a list with a class), not a
SEXPTYPE.
Length(SexpLengthError)
Length did not match the expected one.
Na(SexpNaError)
Missing value encountered where disallowed.
InvalidValue(String)
Value is syntactically valid but semantically invalid (e.g. parse error).
MissingField(String)
A required field was missing from a named list.
DuplicateName(String)
A named list has duplicate non-empty names.
MatchArg(MatchArgError)
A match_arg choice did not match (from #[derive(MatchArg)]’s
TryFromSexp), kept whole so the argument error names the choices.
Condition(RError)
A value a check refused with its own message, classes and fields,
typically a TryFromSexpElement::check_sexp
(#[try_from_sexp(validate = ...)]). Any
RConditionData type, an
RError or a #[derive(RCondition)]
type, converts into it with ?.
As an argument error it keeps the parameter context: the message is
'<p>' must be <expected>: <the RError's message>, the classes come
before the crate’s conversion_error_class, the fields are spliced in
next to e$param and e$rust_type, and the call is the wrapper’s
(RError::without_call has
no effect here, as for any argument error). Inside an Either it is
reported, classes and fields included, whenever the other arm refused
the kind of value.
Implementations§
Source§impl SexpError
impl SexpError
Sourcepub(crate) fn r_expectation(&self) -> Option<String>
pub(crate) fn r_expectation(&self) -> Option<String>
What the value should have been, in R terms, when the error itself
knows and the argument’s Rust type does not tell the macro (#1594): a
match_arg choice (one of "fast", "slow"), a class (a data frame), or an Either whose arms both refused the kind of value
(one of "fast", "slow", or numeric). The generated wrapper then
writes '<p>' must be <this>: <reason> instead of
invalid '<p>' argument: <reason>. A type error alone gives none: the
SEXPTYPE it expected is the storage the conversion reads, which for
an opaque type need not be all it accepts.
Sourcepub(crate) fn r_reason(&self, expected_known: bool) -> String
pub(crate) fn r_reason(&self, expected_known: bool) -> String
The reason of this conversion error in R terms, the text after
'<p>' must be <expected>: in an argument error (#1591). Display
is written for the package author (SEXPTYPE names, invalid value: );
this says what was wrong with the value:
| error | expected_known | reason |
|---|---|---|
| type | yes | got character |
| type | no | expected integer, got character |
| class | yes | got list |
| class | no | expected a data frame, got list |
| length | yes | got length 2 |
| length | no | expected length 1, got length 2 |
| NA | either | NA is not allowed |
| invalid value | either | the value’s own text, without invalid value: |
| missing field / duplicate name | either | missing field 'x' / duplicate name 'x' |
match_arg | yes | got "zzz", got numeric, got length 2, NA is not allowed |
match_arg | no | expected one of "a", "b", got "zzz" |
a check’s refusal (SexpError::Condition) | either | its own message |
Either | either | see below |
expected_known says whether the text before the reason already
states what the value should be ('x' must be a single integer); the
reason then does not repeat it. A per-element reason inside a batched
message is worded with expected_known = false.
Both branches of an Either failed. A type or class error, or a
match_arg refusal of a value that is not a string or factor, means
the value was not of that branch’s kind at all; any other error means
it was, and failed later (length, NA, value), which is the more useful
reason. So: when both branches refused the kind, one reason for the
value’s type (got numeric, or expected integer or character, got numeric, expected one of "a", "b", or numeric, got logical); when
exactly one did, the other branch’s reason; otherwise both branches’
reasons, once if they agree, else joined with ; .
Sourcepub(crate) fn reported_conditions(&self) -> Vec<&RError>
pub(crate) fn reported_conditions(&self) -> Vec<&RError>
The SexpError::Condition refusals whose reasons
r_reason reports, left arm first: the error itself
when it is one, and inside an Either the refusals of the arm (or
arms) whose reason is reported. Their classes and fields go on the
argument error.
Trait Implementations§
Source§impl ConversionErrBuiltin for SexpError
A SexpError also carries the classes and fields of the check refusals
(SexpError::Condition) whose
reasons its message reports, directly or from an Either arm.
impl ConversionErrBuiltin for SexpError
A SexpError also carries the classes and fields of the check refusals
(SexpError::Condition) whose
reasons its message reports, directly or from an Either arm.
fn __mx_conversion_parts(&self, expected_known: bool) -> ErrParts
Source§impl ConversionExpectBuiltin for SexpError
impl ConversionExpectBuiltin for SexpError
fn __mx_conversion_expectation(&self) -> Option<String>
Source§impl Error for SexpError
impl Error for SexpError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Source§#[doc(hidden)]fn type_id(&self, _: Internal) -> TypeIdwhere
Self: 'static,
#[doc(hidden)]fn type_id(&self, _: Internal) -> TypeIdwhere
Self: 'static,
error_type_id)TypeId of self.1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl<E: RConditionData> From<E> for SexpError
Any classed error (an RError, a #[derive(RCondition)] type)
converts into a SexpError::Condition
with its message, classes, fields and call choice, so a newtype’s
check_sexp can refuse with it
and a conversion whose error converts into SexpError keeps its classes.
impl<E: RConditionData> From<E> for SexpError
Any classed error (an RError, a #[derive(RCondition)] type)
converts into a SexpError::Condition
with its message, classes, fields and call choice, so a newtype’s
check_sexp can refuse with it
and a conversion whose error converts into SexpError keeps its classes.
Source§impl From<MatchArgError> for SexpError
Kept whole, so a TryFromSexp whose error is SexpError (the one
#[derive(MatchArg)] emits) still reports the choices.
impl From<MatchArgError> for SexpError
Kept whole, so a TryFromSexp whose error is SexpError (the one
#[derive(MatchArg)] emits) still reports the choices.
Source§fn from(e: MatchArgError) -> Self
fn from(e: MatchArgError) -> Self
Source§impl From<SexpClassError> for SexpError
impl From<SexpClassError> for SexpError
Source§fn from(e: SexpClassError) -> Self
fn from(e: SexpClassError) -> Self
Source§impl From<SexpLengthError> for SexpError
impl From<SexpLengthError> for SexpError
Source§fn from(e: SexpLengthError) -> Self
fn from(e: SexpLengthError) -> Self
Source§impl From<SexpNaError> for SexpError
impl From<SexpNaError> for SexpError
Source§fn from(e: SexpNaError) -> Self
fn from(e: SexpNaError) -> Self
Source§impl From<SexpTypeError> for SexpError
impl From<SexpTypeError> for SexpError
Source§fn from(e: SexpTypeError) -> Self
fn from(e: SexpTypeError) -> Self
Auto Trait Implementations§
impl Freeze for SexpError
impl RefUnwindSafe for SexpError
impl Send for SexpError
impl Sync for SexpError
impl Unpin for SexpError
impl UnsafeUnpin for SexpError
impl UnwindSafe for SexpError
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<T> RDebug for Twhere
T: Debug,
impl<T> RDebug for Twhere
T: Debug,
Source§impl<T> RError for Twhere
T: Error,
impl<T> RError for Twhere
T: Error,
Source§fn error_message(&self) -> String
fn error_message(&self) -> String
Source§fn error_chain(&self) -> Vec<String>
fn error_chain(&self) -> Vec<String>
Source§fn error_chain_length(&self) -> i32
fn error_chain_length(&self) -> i32
Source§#[doc(hidden)]unsafe extern "C" fn __RError_error_message_shim(
data: *mut c_void,
argc: i32,
argv: *const SEXP,
) -> SEXP
#[doc(hidden)]unsafe extern "C" fn __RError_error_message_shim(
data: *mut c_void,
argc: i32,
argv: *const SEXP,
) -> SEXP
RError::error_message. Read moreSource§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
Size for each variant:
Type: 16 bytesClass: 32 bytesLength: 24 bytesNa: 12 bytesInvalidValue: 32 bytesMissingField: 32 bytesDuplicateName: 32 bytesMatchArg: 64 bytesCondition: 104 bytes