Skip to main content

AlienError

Struct AlienError 

Source
pub struct AlienError<T = GenericError>{
    pub code: String,
    pub message: String,
    pub context: Option<Value>,
    pub retryable: bool,
    pub internal: bool,
    pub http_status_code: Option<u16>,
    pub source: Option<Box<AlienError<GenericError>>>,
    pub error: Option<T>,
}
Expand description

Canonical error container that provides a structured way to represent errors with rich metadata including error codes, human-readable messages, context, and chaining capabilities for error propagation.

This struct is designed to be both machine-readable and user-friendly, supporting serialization for API responses and detailed error reporting in distributed systems.

Fields§

§code: String

A unique identifier for the type of error.

This should be a short, machine-readable string that can be used by clients to programmatically handle different error types. Examples: “NOT_FOUND”, “VALIDATION_ERROR”, “TIMEOUT”

§message: String

Human-readable error message.

This message should be clear and actionable for developers or end-users, providing context about what went wrong and potentially how to fix it.

§context: Option<Value>

Additional diagnostic information about the error context.

This optional field can contain structured data providing more details about the error, such as validation errors, request parameters that caused the issue, or other relevant context information.

§retryable: bool

Indicates whether the operation that caused the error should be retried.

When true, the error is transient and the operation might succeed if attempted again. When false, retrying the same operation is unlikely to succeed without changes.

§internal: bool

Indicates if this is an internal error that should not be exposed to users.

When true, this error contains sensitive information or implementation details that should not be shown to end-users. Such errors should be logged for debugging but replaced with generic error messages in responses.

§http_status_code: Option<u16>

HTTP status code for this error.

Used when converting the error to an HTTP response. If None, falls back to the error type’s default status code or 500.

§source: Option<Box<AlienError<GenericError>>>

The underlying error that caused this error, creating an error chain.

This allows for proper error propagation and debugging by maintaining the full context of how an error occurred through multiple layers of an application.

§error: Option<T>

The original error for pattern matching

Implementations§

Source§

impl<T> AlienError<T>

Source

pub fn new(meta: T) -> Self

Create an AlienError from an AlienErrorData implementor

Source§

impl AlienError<GenericError>

Source

pub fn from_std(err: &(dyn StdError + 'static)) -> Self

Create an AlienError from a standard error

Source§

impl<T> AlienError<T>

Source

pub fn into_generic(self) -> AlienError<GenericError>

Convert this AlienError to AlienError without losing data

Trait Implementations§

Source§

impl<T> Clone for AlienError<T>

Source§

fn clone(&self) -> AlienError<T>

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

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E> ContextError<E> for AlienError<E>
where E: AlienErrorData + Clone + Debug + Serialize + 'static + Send + Sync,

Source§

fn context<M: AlienErrorData + Clone + Debug + Serialize>( self, meta: M, ) -> AlienError<M>

Add context to an AlienError, wrapping it with a new error
Source§

impl<T> Debug for AlienError<T>

Source§

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

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

impl<'de, T> Deserialize<'de> for AlienError<T>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Display for AlienError<T>

Source§

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

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

impl<T> Error for AlienError<T>

Source§

fn source(&self) -> Option<&(dyn StdError + '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<T> PartialEq for AlienError<T>

Source§

fn eq(&self, other: &AlienError<T>) -> bool

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

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<T> Serialize for AlienError<T>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> Eq for AlienError<T>

Source§

impl<T> StructuralPartialEq for AlienError<T>

Auto Trait Implementations§

§

impl<T> Freeze for AlienError<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for AlienError<T>
where T: RefUnwindSafe,

§

impl<T> Send for AlienError<T>
where T: Send,

§

impl<T> Sync for AlienError<T>
where T: Sync,

§

impl<T> Unpin for AlienError<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for AlienError<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for AlienError<T>
where T: UnwindSafe,

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> 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<E> IntoAlienErrorDirect for E
where E: Error + 'static,

Source§

fn into_alien_error(self) -> AlienError

Convert a standard error into an AlienError
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,