Skip to main content

SexpError

Enum SexpError 

Source
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

Source

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.

Source

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:

errorexpected_knownreason
typeyesgot character
typenoexpected integer, got character
classyesgot list
classnoexpected a data frame, got list
lengthyesgot length 2
lengthnoexpected length 1, got length 2
NAeitherNA is not allowed
invalid valueeitherthe value’s own text, without invalid value:
missing field / duplicate nameeithermissing field 'x' / duplicate name 'x'
match_argyesgot "zzz", got numeric, got length 2, NA is not allowed
match_argnoexpected one of "a", "b", got "zzz"
a check’s refusal (SexpError::Condition)eitherits own message
Eithereithersee 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 ; .

Source

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 Clone for SexpError

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 ConversionArgMessageBuiltin for SexpError

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.

Source§

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

Source§

impl ConversionExpectBuiltin for SexpError

Source§

impl Debug for SexpError

Source§

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

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

impl Display for SexpError

Source§

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

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

impl Error for SexpError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
Source§

#[doc(hidden)]
fn type_id(&self, _: Internal) -> TypeId
where Self: 'static,

🔬This is a nightly-only experimental API. (error_type_id)
Gets the TypeId of self.
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
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.

Source§

fn from(e: E) -> Self

Converts to this type from the input type.
Source§

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

Converts to this type from the input type.
Source§

impl From<SexpClassError> for SexpError

Source§

fn from(e: SexpClassError) -> Self

Converts to this type from the input type.
Source§

impl From<SexpLengthError> for SexpError

Source§

fn from(e: SexpLengthError) -> Self

Converts to this type from the input type.
Source§

impl From<SexpNaError> for SexpError

Source§

fn from(e: SexpNaError) -> Self

Converts to this type from the input type.
Source§

impl From<SexpTypeError> for SexpError

Source§

fn from(e: SexpTypeError) -> Self

Converts to this type from the input type.

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<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> RError for T
where T: Error,

Source§

fn error_message(&self) -> String

Get the error message (Display representation).
Source§

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

Get all error messages in the chain, from outermost to innermost.
Source§

fn error_chain_length(&self) -> i32

Get the number of errors in the chain.
Source§

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

Method shim for RError::error_message. Read more
Source§

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

Method shim for RError::error_chain. Read more
Source§

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

Method shim for RError::error_chain_length. 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

Size for each variant:

  • Type: 16 bytes
  • Class: 32 bytes
  • Length: 24 bytes
  • Na: 12 bytes
  • InvalidValue: 32 bytes
  • MissingField: 32 bytes
  • DuplicateName: 32 bytes
  • MatchArg: 64 bytes
  • Condition: 104 bytes