Struct Error

Source
pub struct Error { /* private fields */ }
Expand description

Error type for CEL operations.

This is the main error type used throughout the cel-cxx library. It represents an error condition in CEL expression compilation or evaluation, modeled after the absl::Status type from the Google Abseil library.

§Examples

§Creating Errors

use cel_cxx::{Error, Code};

let error = Error::invalid_argument("Expression syntax is invalid");
assert_eq!(error.code(), Code::InvalidArgument);

§Handling Errors

use cel_cxx::*;

match Env::builder().build()?.compile("invalid expression!!") {
    Ok(program) => println!("Compiled successfully"),
    Err(e) => {
        eprintln!("Error: {}", e);
        eprintln!("Error code: {:?}", e.code());
    }
}

Implementations§

Source§

impl Error

Source

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

Creates a new error with the specified code and message.

This is the fundamental constructor for creating errors. Most users should prefer the specific constructor methods like invalid_argument, not_found, etc., which are more descriptive.

§Arguments
  • code - The error code indicating the type of error
  • message - A descriptive message explaining the error
§Examples
use cel_cxx::{Error, Code};

let error = Error::new(Code::InvalidArgument, "Invalid input provided");
assert_eq!(error.code(), Code::InvalidArgument);
assert_eq!(error.message(), "Invalid input provided");
Source

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

Creates an “ok” status with the given message.

This is rarely used for actual errors, but may be useful in some contexts where a status needs to indicate success with additional information.

§Examples
use cel_cxx::Error;

let status = Error::ok("Operation completed successfully");
Source

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

Creates a “cancelled” error with the given message.

§Examples
use cel_cxx::Error;

let error = Error::cancelled("Operation was cancelled by user");
Source

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

Creates an “unknown” error with the given message.

This is useful when converting from other error types where the specific category cannot be determined.

§Examples
use cel_cxx::Error;

let error = Error::unknown("An unexpected error occurred");
Source

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

Creates an “invalid argument” error with the given message.

This is commonly used for CEL compilation errors due to invalid syntax or malformed expressions.

§Examples
use cel_cxx::Error;

let error = Error::invalid_argument("Expression contains invalid syntax");
Source

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

Creates a “deadline exceeded” error with the given message.

§Examples
use cel_cxx::Error;

let error = Error::deadline_exceeded("Operation took too long to complete");
Source

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

Creates a “not found” error with the given message.

This is commonly used when a referenced variable or function is not found in the current environment.

§Examples
use cel_cxx::Error;

let error = Error::not_found("Variable 'x' is not declared");
Source

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

Creates an “already exists” error with the given message.

§Examples
use cel_cxx::Error;

let error = Error::already_exists("Function 'myFunc' is already registered");
Source

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

Creates a “permission denied” error with the given message.

§Examples
use cel_cxx::Error;

let error = Error::permission_denied("Access to this resource is denied");
Source

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

Creates a “resource exhausted” error with the given message.

This can be used when evaluation hits resource limits such as memory or computation time.

§Examples
use cel_cxx::Error;

let error = Error::resource_exhausted("Memory limit exceeded during evaluation");
Source

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

Creates a “failed precondition” error with the given message.

This indicates that the operation cannot be performed because the system is not in the required state. See the documentation for Code::FailedPrecondition for guidance on when to use this vs. other error codes.

§Examples
use cel_cxx::Error;

let error = Error::failed_precondition("Environment must be built before compilation");
Source

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

Creates an “aborted” error with the given message.

This indicates that the operation was aborted, typically due to a concurrency issue or transaction conflict.

§Examples
use cel_cxx::Error;

let error = Error::aborted("Transaction was aborted due to conflict");
Source

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

Creates an “out of range” error with the given message.

This indicates that the operation attempted to access something outside of valid bounds, such as array indices or valid value ranges.

§Examples
use cel_cxx::Error;

let error = Error::out_of_range("Index 10 is out of range for array of length 5");
Source

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

Creates an “unimplemented” error with the given message.

This indicates that the requested operation is not implemented or not supported in the current context.

§Examples
use cel_cxx::Error;

let error = Error::unimplemented("This feature is not yet implemented");
Source

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

Creates an “internal” error with the given message.

This indicates an internal error that should not normally occur. It typically indicates a bug in the implementation.

§Examples
use cel_cxx::Error;

let error = Error::internal("Internal invariant violated");
Source

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

Creates an “unavailable” error with the given message.

This indicates that the service is temporarily unavailable and the operation should be retried later.

§Examples
use cel_cxx::Error;

let error = Error::unavailable("Service is temporarily unavailable");
Source

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

Creates a “data loss” error with the given message.

This indicates that data has been lost or corrupted in an unrecoverable way.

§Examples
use cel_cxx::Error;

let error = Error::data_loss("Critical data has been corrupted");
Source

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

Creates an “unauthenticated” error with the given message.

This indicates that the operation requires authentication credentials that are missing or invalid.

§Examples
use cel_cxx::Error;

let error = Error::unauthenticated("Valid authentication credentials required");
Source

pub fn code(&self) -> Code

Returns the error code for this error.

§Examples
use cel_cxx::{Error, Code};

let error = Error::invalid_argument("Bad input");
assert_eq!(error.code(), Code::InvalidArgument);
Source

pub fn message(&self) -> &str

Returns the error message for this error.

§Examples
use cel_cxx::Error;

let error = Error::invalid_argument("Bad input");
assert_eq!(error.message(), "Bad input");
Source

pub fn from_std_error(err: Box<dyn Error + Send + Sync + 'static>) -> Self

Creates a CEL error from a standard library error.

This method attempts to extract meaningful error information from standard library errors and convert them to CEL errors. It inspects the error source chain for recognizable error types.

§Arguments
  • err - The standard library error to convert
§Returns

A CEL Error with an appropriate error code and message. If the error type is not recognized, it will be mapped to Code::Unknown.

§Examples
use cel_cxx::Error;
use std::io;

let io_error = io::Error::new(io::ErrorKind::NotFound, "File not found");
let cel_error = Error::from_std_error(Box::new(io_error));
Source

pub fn try_from_std_error( err: Box<dyn Error + Send + Sync + 'static>, ) -> Result<Self, Box<dyn Error + Send + Sync + 'static>>

Attempts to create a CEL error from a standard library error.

This method is similar to from_std_error but returns the original error if it cannot be converted to a CEL error.

§Arguments
  • err - The standard library error to convert
§Returns

Ok(Error) if the conversion was successful, or Err(original_error) if the error type could not be recognized.

§Downcast Stability

This function does not provide any stability guarantees around how it will downcast errors into status codes. The conversion logic may change in future versions.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Error

Returns a duplicate of the value. Read more
1.0.0 · Source§

const 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

1.30.0 · Source§

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

Returns the lower-level source of this error, if any. Read more
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 Value

Source§

fn from(value: Error) -> Self

Converts to this type from the input type.
Source§

impl From<FromMapKeyError> for Error

Source§

fn from(error: FromMapKeyError) -> Self

Converts to this type from the input type.
Source§

impl From<FromValueError> for Error

Source§

fn from(error: FromValueError) -> Self

Converts to this type from the input type.
Source§

impl From<InvalidMapKeyType> for Error

Source§

fn from(error: InvalidMapKeyType) -> Self

Converts to this type from the input type.
Source§

impl FromValue for &Error

Source§

type Output<'a> = &'a Error

The output type for the from_value method. Read more
Source§

fn from_value<'a>(value: &'a Value) -> Result<Self::Output<'a>, FromValueError>

Attempts to convert a CEL Value into this type. Read more
Source§

impl FromValue for Error

Source§

type Output<'a> = Error

The output type for the from_value method. Read more
Source§

fn from_value<'a>(value: &'a Value) -> Result<Self::Output<'a>, FromValueError>

Attempts to convert a CEL Value into this type. Read more
Source§

impl Hash for Error

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoValue for Error

Source§

fn into_value(self) -> Value

Converts this value into a CEL Value. Read more
Source§

impl PartialEq for Error

Source§

fn eq(&self, other: &Error) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> TryFrom<&'a Value> for &'a Error

Source§

type Error = FromValueError

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

fn try_from(value: &'a Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for Error

Source§

type Error = FromValueError

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

fn try_from(value: &Value) -> Result<Self, <Self as TryFrom<&Value>>::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Error

Source§

type Error = FromValueError

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

fn try_from(value: Value) -> Result<Self, <Self as TryFrom<Value>>::Error>

Performs the conversion.
Source§

impl TypedValue for Error

Source§

fn value_type() -> ValueType

Returns the CEL type for this value type. Read more
Source§

impl Eq for Error

Source§

impl StructuralPartialEq for Error

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnwindSafe 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<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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<E> IntoError for E
where E: Error + Send + Sync + 'static,

Source§

fn into_error(self) -> Error

Converts this value into a CEL error. Read more
Source§

impl<T> IntoResult for T
where T: IntoValue + TypedValue,

Source§

fn into_result(self) -> Result<Value, Error>

Convert the value into a CEL result.
Source§

fn value_type() -> ValueType

Get the CEL type of the resulting value.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more