Skip to main content

ServiceError

Enum ServiceError 

Source
pub enum ServiceError {
Show 15 variants Database { message: String, source: Option<Box<dyn Error + Send + Sync>>, }, NotFound { resource_type: String, identifier: String, }, InvalidInput { message: String, field: Option<String>, }, Unauthenticated(String), PermissionDenied(String), BusinessRule(String), ExternalService { service: String, message: String, source: Option<Box<dyn Error + Send + Sync>>, }, Configuration(String), RateLimitExceeded(String), Conflict(String), Cache { message: String, source: Option<Box<dyn Error + Send + Sync>>, }, Timeout { operation: String, timeout_ms: u64, }, ResourceExhausted { resource: String, message: String, }, ValidationErrors(HashMap<String, Vec<String>>), Internal { message: String, source: Option<Box<dyn Error + Send + Sync>>, },
}
Expand description

Unified error type for Pleme services

Follows Railway-Oriented Programming pattern where errors flow through a separate “error track” from the success track.

Variants§

§

Database

Database operation failed

Fields

§message: String
§source: Option<Box<dyn Error + Send + Sync>>
§

NotFound

Resource not found

Fields

§resource_type: String
§identifier: String
§

InvalidInput

Invalid input or validation error

Fields

§message: String
§

Unauthenticated(String)

Authentication required

§

PermissionDenied(String)

Permission denied

§

BusinessRule(String)

Business logic constraint violated

§

ExternalService

External service error (e.g., payment gateway, email service)

Fields

§service: String
§message: String
§source: Option<Box<dyn Error + Send + Sync>>
§

Configuration(String)

Configuration error

§

RateLimitExceeded(String)

Rate limit exceeded

§

Conflict(String)

Conflict (e.g., duplicate resource)

§

Cache

Cache operation failed

Fields

§message: String
§source: Option<Box<dyn Error + Send + Sync>>
§

Timeout

Operation timeout

Fields

§operation: String
§timeout_ms: u64
§

ResourceExhausted

Resource exhausted (memory, disk, connections, etc.)

Fields

§resource: String
§message: String
§

ValidationErrors(HashMap<String, Vec<String>>)

Validation errors for multiple fields

§

Internal

Internal server error (catch-all)

Fields

§message: String
§source: Option<Box<dyn Error + Send + Sync>>

Implementations§

Source§

impl ServiceError

Source

pub fn database<E>(message: impl Into<String>, error: E) -> Self
where E: Error + Send + Sync + 'static,

Create a database error with context

Source

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

Create a database error without source

Source

pub fn not_found(resource_type: impl Into<String>, id: impl Display) -> Self

Create a not found error

Source

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

Create an invalid input error

Source

pub fn invalid_field( field: impl Into<String>, message: impl Into<String>, ) -> Self

Create an invalid input error with field name

Source

pub fn external_service<E>( service: impl Into<String>, message: impl Into<String>, error: E, ) -> Self
where E: Error + Send + Sync + 'static,

Create an external service error

Source

pub fn internal<E>(message: impl Into<String>, error: E) -> Self
where E: Error + Send + Sync + 'static,

Create an internal error with context

Source

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

Create an internal error without source

Source

pub fn cache<E>(message: impl Into<String>, error: E) -> Self
where E: Error + Send + Sync + 'static,

Create a cache error with context

Source

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

Create a cache error without source

Source

pub fn timeout(operation: impl Into<String>, timeout_ms: u64) -> Self

Create a timeout error

Source

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

Create a resource exhausted error

Source

pub fn is_retryable(&self) -> bool

Check if error is retryable (for exponential backoff)

Source

pub fn is_severe(&self) -> bool

Check if error should be logged at error level

Trait Implementations§

Source§

impl Debug for ServiceError

Source§

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

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

impl Display for ServiceError

Source§

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

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

impl Error for ServiceError

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 ServiceError

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for ServiceError

Source§

fn from(error: ParseError) -> 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> 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> 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.