Skip to main content

Error

Struct Error 

Source
#[non_exhaustive]
pub struct Error { pub kind: ErrorKind, /* private fields */ }
Expand description

Error returned by every crate::Engine operation.

The kind field carries the failure category and any variant-specific payload. operator and node_ids are populated by the public evaluate* entry points: operator names the innermost operator that failed, and node_ids is a breadcrumb of compiled-node ids from the failure site toward the root (leaf-to-root). Use Error::resolve_path to translate the ids into structured crate::PathSteps callers can act on.

§Wire format

Error serialises as: {"type": <kind tag>, "message": <Display>, ...kind-extras, "operator"?, "node_ids"?}. operator is omitted when None; node_ids is omitted when empty. JS consumers can JSON.parse(err) and switch on err.type.

§Source chains

std::error::Error::source returns Some only for ErrorKind::Custom — the variant produced by Error::wrap. Every other variant carries a flat string or structured payload, not a typed cause. To attach a typed source error, wrap it via Error::wrap instead of constructing e.g. Error::invalid_arguments("...") directly.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§kind: ErrorKind

What went wrong. Pattern-matched by callers; stays public.

Implementations§

Source§

impl Error

Source

pub fn new(kind: ErrorKind) -> Self

Construct an Error with the given kind and no contextual metadata.

Source

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

The operator that failed, when known: the innermost operator on Self::node_ids, so a failing custom operator nested inside built-ins is named itself. The same on every evaluation path, traced or not. When no node on the path has an operator name, the rule’s root operator stands in.

Returns None for parse/compile errors and for raw constructor sites that didn’t call Self::with_operator.

Source

pub fn node_ids(&self) -> &[u32]

Breadcrumb of compiled-node ids from the failure site toward the root (leaf-to-root). Returns an empty slice when the error came from parse/compile or wasn’t routed through the public evaluate* path. Use Self::resolve_path to convert ids into named crate::PathSteps.

Source

pub fn tag(&self) -> &'static str

Get a stable string tag for the error kind. Stable across releases. The name of Self::code.

Source

pub fn code(&self) -> ErrorCode

What kind of error this is, without its payload. See ErrorCode.

Source

pub fn with_operator(self, operator: impl Into<Cow<'static, str>>) -> Self

Attach the name of the operator that failed and return self. An error that leaves an evaluation already named keeps that name.

Accepts anything convertible to Cow<'static, str> — passing a &'static str literal stays zero-allocation; a String becomes Cow::Owned (one move, no copy).

Source

pub fn with_node_ids(self, ids: Vec<u32>) -> Self

Attach the breadcrumb path and return self.

Takes a Vec<u32> of compiled-node ids (leaf-to-root). The internal storage is private; future versions may swap its layout without an API change.

Source

pub fn resolve_path(&self, compiled: &Logic) -> Vec<PathStep>

Resolve the raw Self::node_ids breadcrumb into structured crate::PathSteps (root-to-leaf). Walks the compiled tree once.

Returns an empty vector when self.node_ids is empty. Ids absent from the compiled tree (e.g. when the error came from compile-time, before evaluation populated the breadcrumb) are skipped.

Why on demand: an earlier design eagerly cached the resolved steps on Error so callers could read them without holding the Logic. That walk allocates a HashMap of every node + a String JSON pointer per node, and paying it on every boundary error inflated error-heavy benchmark suites by 17×. Resolving on demand at the catch site puts the cost where the caller actually needs the data — and most callers either inspect raw Self::node_ids only, or already hold the compiled Logic at the catch site.

Source

pub fn invalid_operator(name: impl Into<Cow<'static, str>>) -> Self

Shorthand for ErrorKind::InvalidOperator(name).into().

Source

pub fn invalid_arguments(msg: impl Into<Cow<'static, str>>) -> Self

Shorthand for ErrorKind::InvalidArguments(msg).into().

Source

pub fn variable_not_found(name: impl Into<Cow<'static, str>>) -> Self

Shorthand for ErrorKind::VariableNotFound(name).into().

Source

pub fn invalid_context_level(level: isize) -> Self

Shorthand for ErrorKind::InvalidContextLevel(level).into().

Source

pub fn type_error(msg: impl Into<Cow<'static, str>>) -> Self

Shorthand for ErrorKind::TypeError(msg).into().

Source

pub fn arithmetic_error(msg: impl Into<Cow<'static, str>>) -> Self

Shorthand for ErrorKind::ArithmeticError(msg).into().

Source

pub fn custom_message(msg: impl Into<String>) -> Self

Shorthand for a message-only ErrorKind::Custom. Equivalent to Self::wrap with a string-shaped error inside. Reach for Self::wrap directly when you have a typed std::error::Error to preserve.

Source

pub fn wrap<E: Error + Send + Sync + 'static>(err: E) -> Self

Wrap any std::error::Error + Send + Sync + 'static into an ErrorKind::Custom, preserving the source chain so consumers can walk it via std::error::Error::source:

ⓘ
some_io_call().map_err(Error::wrap)?;

The original error stays inspectable: error.source() returns Some(&original). Standard chain-walking via std::error::Error::source applies all the way down.

Wrapping an existing Error is a no-op — the input is returned unchanged rather than producing Custom(Custom(...)).

Source

pub fn parse_error(msg: impl Into<Cow<'static, str>>) -> Self

Shorthand for ErrorKind::ParseError(msg).into().

Source

pub fn thrown(value: OwnedDataValue) -> Self

Shorthand for ErrorKind::Thrown(value).into().

Source

pub fn thrown_value(&self) -> Option<&OwnedDataValue>

If this is an ErrorKind::Thrown, return its payload. Convenience accessor so consumers (loggers, structured-error walkers, the test runner) don’t have to pattern-match on the kind themselves.

Source

pub fn format_error(msg: impl Into<Cow<'static, str>>) -> Self

Shorthand for ErrorKind::FormatError(msg).into().

Source

pub fn index_out_of_bounds(index: isize, length: usize) -> Self

Shorthand for ErrorKind::IndexOutOfBounds { index, length }.into().

Source

pub fn configuration_error(msg: impl Into<Cow<'static, str>>) -> Self

Shorthand for ErrorKind::ConfigurationError(msg).into().

Trait Implementations§

Source§

impl Clone for Error

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 Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

Source§

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

Returns the wrapped source error, but only for ErrorKind::Custom.

All other ErrorKind variants carry a flat Cow<'static, str> payload (or a structured value, in Thrown / IndexOutOfBounds) rather than a typed cause, so they have no dyn Error to chain to. To attach a typed source, wrap your error via Error::wrap — that produces an ErrorKind::Custom whose source() returns Some(&original) and whose Display matches the original.

use datalogic_rs::Error;
use std::error::Error as _;

fn read_config() -> std::io::Result<String> {
    Err(std::io::Error::other("disk fell off the cliff"))
}

let err = read_config().map_err(Error::wrap).unwrap_err();
// The original io::Error survives the wrap and can be walked.
let source = err.source().unwrap();
assert!(source.to_string().contains("disk"));
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 From<Error> for Error

Available on crate feature serde_json only.
Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ErrorKind> for Error

Source§

fn from(kind: ErrorKind) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for Error

Source§

fn from(err: ParseError) -> Self

Converts to this type from the input type.
Source§

impl Serialize for Error

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.