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
impl Error
Sourcepub fn new(code: Code, message: impl Into<String>) -> Self
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 errormessage
- 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");
Sourcepub fn ok(message: impl Into<String>) -> Self
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");
Sourcepub fn cancelled(message: impl Into<String>) -> Self
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");
Sourcepub fn unknown(message: impl Into<String>) -> Self
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");
Sourcepub fn invalid_argument(message: impl Into<String>) -> Self
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");
Sourcepub fn deadline_exceeded(message: impl Into<String>) -> Self
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");
Sourcepub fn not_found(message: impl Into<String>) -> Self
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");
Sourcepub fn already_exists(message: impl Into<String>) -> Self
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");
Sourcepub fn permission_denied(message: impl Into<String>) -> Self
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");
Sourcepub fn resource_exhausted(message: impl Into<String>) -> Self
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");
Sourcepub fn failed_precondition(message: impl Into<String>) -> Self
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");
Sourcepub fn aborted(message: impl Into<String>) -> Self
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");
Sourcepub fn out_of_range(message: impl Into<String>) -> Self
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");
Sourcepub fn unimplemented(message: impl Into<String>) -> Self
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");
Sourcepub fn internal(message: impl Into<String>) -> Self
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");
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");
Sourcepub fn data_loss(message: impl Into<String>) -> Self
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");
Sourcepub fn unauthenticated(message: impl Into<String>) -> Self
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");
Sourcepub fn code(&self) -> Code
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);
Sourcepub fn message(&self) -> &str
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");
Sourcepub fn from_std_error(err: Box<dyn Error + Send + Sync + 'static>) -> Self
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));
Sourcepub fn try_from_std_error(
err: Box<dyn Error + Send + Sync + 'static>,
) -> Result<Self, Box<dyn Error + Send + Sync + 'static>>
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 Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<FromMapKeyError> for Error
impl From<FromMapKeyError> for Error
Source§fn from(error: FromMapKeyError) -> Self
fn from(error: FromMapKeyError) -> Self
Source§impl From<FromValueError> for Error
impl From<FromValueError> for Error
Source§fn from(error: FromValueError) -> Self
fn from(error: FromValueError) -> Self
Source§impl From<InvalidMapKeyType> for Error
impl From<InvalidMapKeyType> for Error
Source§fn from(error: InvalidMapKeyType) -> Self
fn from(error: InvalidMapKeyType) -> Self
Source§impl TypedValue for Error
impl TypedValue for Error
Source§fn value_type() -> ValueType
fn value_type() -> ValueType
impl Eq for Error
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> 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,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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