pub struct ModelError {
error_type: ModelErrorType,
message: String,
source: Option<Error>,
span_trace: SpanTrace,
backtrace: Backtrace,
}
Expand description
Error type used by all models. Used as the error type in ModelError, which is used by all the controllers in the application.
All the information in the error is meant to be seen by the user. The type of error is determined by the ModelErrorType enum, which is stored inside this struct.
§Examples
§Usage without source error
if erroneous_condition {
return Err(ModelError::new(
ModelErrorType::PreconditionFailed,
"The user has not enrolled to this course".to_string(),
None,
));
}
§Usage with a source error
Used when calling a function that returns an error that cannot be automatically converted to an ModelError. (See impl From<X>
implementations on this struct.)
some_function_returning_an_error().map_err(|original_error| {
ModelError::new(
ModelErrorType::Generic,
"Everything went wrong".to_string(),
Some(original_error.into()),
)
})?;
Fields§
§error_type: ModelErrorType
§message: String
§source: Option<Error>
Original error that caused this error.
span_trace: SpanTrace
A trace of tokio tracing spans, generated automatically when the error is generated.
backtrace: Backtrace
Stack trace, generated automatically when the error is created.
Trait Implementations§
Source§impl BackendError for ModelError
impl BackendError for ModelError
type ErrorType = ModelErrorType
fn new<M: Into<String>, S: Into<Option<Error>>>( error_type: Self::ErrorType, message: M, source_error: S, ) -> Self
fn backtrace(&self) -> Option<&Backtrace>
fn error_type(&self) -> &Self::ErrorType
fn message(&self) -> &str
fn span_trace(&self) -> &SpanTrace
fn new_with_traces<M: Into<String>, S: Into<Option<Error>>>( error_type: Self::ErrorType, message: M, source_error: S, backtrace: Backtrace, span_trace: SpanTrace, ) -> Self
fn to_different_error<T>( self, new_error_type: <T as BackendError>::ErrorType, new_message: String, ) -> T
Source§impl Debug for ModelError
impl Debug for ModelError
Source§impl Display for ModelError
impl Display for ModelError
Source§impl Error for ModelError
impl Error for ModelError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
Source§fn cause(&self) -> Option<&dyn Error>
fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<Error> for ModelError
impl From<Error> for ModelError
Source§impl From<Error> for ModelError
impl From<Error> for ModelError
Source§impl From<Error> for ModelError
impl From<Error> for ModelError
Source§fn from(err: Error) -> ModelError
fn from(err: Error) -> ModelError
Converts to this type from the input type.
Source§impl From<ParseError> for ModelError
impl From<ParseError> for ModelError
Source§fn from(err: ParseError) -> ModelError
fn from(err: ParseError) -> ModelError
Converts to this type from the input type.
Source§impl From<TryFromIntError> for ModelError
impl From<TryFromIntError> for ModelError
Source§fn from(source: TryFromIntError) -> Self
fn from(source: TryFromIntError) -> Self
Converts to this type from the input type.
Source§impl From<UtilError> for ModelError
impl From<UtilError> for ModelError
Source§impl<T> TryToOptional<T, ModelError> for ModelResult<T>
impl<T> TryToOptional<T, ModelError> for ModelResult<T>
Auto Trait Implementations§
impl Freeze for ModelError
impl !RefUnwindSafe for ModelError
impl Send for ModelError
impl Sync for ModelError
impl Unpin for ModelError
impl !UnwindSafe for ModelError
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
Mutably borrows from an owned value. Read more
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<E> InstrumentError for Ewhere
TracedError<E>: From<E>,
impl<E> InstrumentError for Ewhere
TracedError<E>: From<E>,
Source§type Instrumented = TracedError<E>
type Instrumented = TracedError<E>
The type of the wrapped error after instrumentation
Source§fn in_current_span(self) -> <E as InstrumentError>::Instrumented
fn in_current_span(self) -> <E as InstrumentError>::Instrumented
Instrument an Error by bundling it with a SpanTrace Read more
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>
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 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>
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