Skip to main content

Problem

Struct Problem 

Source
pub struct Problem {
    pub causes: ThinVec<Cause>,
}
Expand description

A problem is a simple wrapper for an error causation chain.

Each link in the chain is a Cause, which is itself a simple wrapper for a CapturedError. Each cause can have any number of attachments.

Though you can iterate a problem directly to access its causes, often it is easier to use one of the many convenience functions in the ProblemImplementation and Causes traits.

Note that this type does not itself implement Error directly, but you can use into_error if compatibility is needed.

For more information and usage examples see the Problemo home page.

Fields§

§causes: ThinVec<Cause>

Causes in order of causation from top to root.

Implementations§

Source§

impl Problem

Source

pub fn new(error: CapturedError) -> Self

Constructor.

Source

pub fn into_error(self) -> ProblemAsError

Add support for Error.

Take care to avoid adding it into a Problem’s causation chain.

Source

pub fn via<ErrorT>(self, error: ErrorT) -> Self
where ErrorT: 'static + Error + Send + Sync,

Adds the error to the top of the causation chain.

Source

pub fn with<AttachmentT>(self, attachment: AttachmentT) -> Self
where AttachmentT: Any + Send + Sync,

Attach to the top cause.

Source

pub fn with_once<AttachmentT>(self, attachment: AttachmentT) -> Self
where AttachmentT: Any + Send + Sync,

Attach only if we don’t already have one of the same type.

Source

pub fn maybe_with<AttachmentT>(self, attachment: Option<AttachmentT>) -> Self
where AttachmentT: Any + Send + Sync,

Attach to the top cause if Some.

Source

pub fn maybe_with_once<AttachmentT>( self, attachment: Option<AttachmentT>, ) -> Self
where AttachmentT: Any + Send + Sync,

Attach to the top cause if Some and we don’t already have one of the same type.

Source

pub fn with_location(self) -> Self

Attach a Location (via Location::caller) if we don’t already have one.

Source

pub fn with_backtrace(self) -> Self

Attach a backtrace if we don’t already have one.

Source

pub fn into_problems(self) -> Problems

Convert into Problems.

Will return the first cause that is a Problems, otherwise will return a new Problems with just self.

Note that this is identical to calling Problems::from(problem).

Trait Implementations§

Source§

impl Attachments for Problem

Source§

fn attachments(&self) -> impl Iterator<Item = &CapturedAttachment>

Iterate attachments.
Source§

fn attachments_of_type<'this, AttachmentT>( &'this self, ) -> impl Iterator<Item = &'this AttachmentT>
where AttachmentT: 'static,

Iterate attachments of a type.
Source§

fn attachment_of_type<AttachmentT>(&self) -> Option<&AttachmentT>
where AttachmentT: 'static,

First attachment of a type.
Source§

impl AttachmentsMut for Problem

Source§

fn attachments_mut(&mut self) -> impl Iterator<Item = &mut CapturedAttachment>

Iterate attachments.
Source§

fn attach<AttachmentT>(&mut self, attachment: AttachmentT)
where AttachmentT: Any + Send + Sync,

Add an attachment.
Source§

fn attachments_of_type_mut<'this, AttachmentT>( &'this mut self, ) -> impl Iterator<Item = &'this mut AttachmentT>
where AttachmentT: 'static,

Iterate attachments of a type.
Source§

fn attachment_of_type_mut<AttachmentT>(&mut self) -> Option<&mut AttachmentT>
where AttachmentT: 'static,

First attachment of a type.
Source§

fn must_attachment_of_type_mut<AttachmentT, DefaultT>( &mut self, default: DefaultT, ) -> &mut AttachmentT
where AttachmentT: 'static + Send + Sync, DefaultT: FnOnce() -> AttachmentT,

First attachment of a type. Read more
Source§

fn attach_once<AttachmentT>(&mut self, attachment: AttachmentT)
where AttachmentT: 'static + Send + Sync,

Add an attachment only if we don’t already have one of its type.
Source§

fn attach_location_once(&mut self)

Add a Location (via Location::caller) attachment if we don’t already have one.
Source§

fn attach_backtrace_once(&mut self)

Available on crate feature backtrace-external only.
Add a backtrace attachment if we don’t already have one.
Source§

impl Causes for Problem

Source§

fn problem(&self) -> &Problem

The problem that owns this causation chain.
Source§

fn iter_causes(&self) -> impl Iterator<Item = &Cause>

Iterate causes in order of causation. Read more
Source§

fn iter_causes_with_error_type<ErrorT>( &self, ) -> impl Iterator<Item = CauseRef<'_, ErrorT>>
where ErrorT: 'static + Error,

Iterate causes with an error of a type. Read more
Source§

fn iter_causes_until_error_type<ErrorT>(&self) -> impl Iterator<Item = &Cause>
where ErrorT: 'static + Error,

Iterate causes in order of causation until (but not including) a cause with an error of a type. Read more
Source§

fn iter_causes_from_error_type<ErrorT>(&self) -> impl Iterator<Item = &Cause>
where ErrorT: 'static + Error,

Iterate causes in order of causation from a cause with an error of a type. Read more
Source§

fn iter_causes_with_error<ErrorT>( &self, error: &ErrorT, ) -> impl Iterator<Item = CauseRef<'_, ErrorT>>
where ErrorT: 'static + Error + PartialEq,

Iterate causes with the error. Read more
Source§

fn iter_causes_with_attachment_type<AttachmentT>( &self, ) -> impl Iterator<Item = (&Cause, &AttachmentT)>
where AttachmentT: 'static,

Iterate causes with an attachment of a type.
Source§

fn cause_with_error_type<ErrorT>(&self) -> Option<CauseRef<'_, ErrorT>>
where ErrorT: 'static + Error,

The first cause with an error of a type. Read more
Source§

fn cause_with_error<ErrorT>( &self, error: &ErrorT, ) -> Option<CauseRef<'_, ErrorT>>
where ErrorT: 'static + Error + PartialEq,

The first cause with the error. Read more
Source§

fn cause_with_attachment_type<AttachmentT>( &self, ) -> Option<(&Cause, &AttachmentT)>
where AttachmentT: 'static,

The first cause with an attachment of a type.
Source§

fn iter_errors(&self) -> impl Iterator<Item = &CapturedError>

Iterate errors in order of causation. Read more
Source§

fn iter_errors_of_type<ErrorT>(&self) -> impl Iterator<Item = &ErrorT>
where ErrorT: 'static + Error,

Iterate errors of a type in order of causation. Read more
Source§

fn error_of_type<ErrorT>(&self) -> Option<&ErrorT>
where ErrorT: 'static + Error,

The first error of a type. Read more
Source§

fn has_error_type<ErrorT>(&self) -> bool
where ErrorT: 'static + Error,

Whether we have an error of a type in the causation chain. Read more
Source§

fn has_error<ErrorT>(&self, error: &ErrorT) -> bool
where ErrorT: 'static + Error + PartialEq,

Whether we have the error in the causation chain. Read more
Source§

impl Debug for Problem

Source§

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

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

impl Default for Problem

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Problem

Source§

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

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

impl From<&Problem> for ExitCode

Source§

fn from(problem: &Problem) -> Self

Converts to this type from the input type.
Source§

impl<ErrorT> From<ErrorT> for Problem
where ErrorT: 'static + Error + Send + Sync,

Source§

fn from(error: ErrorT) -> Self

Converts to this type from the input type.
Source§

impl From<Problem> for Error

Available on crate feature anyhow only.
Source§

fn from(problem: Problem) -> Self

Converts to this type from the input type.
Source§

impl From<Problem> for Error

Available on crate feature wasmtime only.
Source§

fn from(problem: Problem) -> Self

Converts to this type from the input type.
Source§

impl From<Problem> for ExitCode

Source§

fn from(problem: Problem) -> Self

Converts to this type from the input type.
Source§

impl From<Problem> for ProblemAsError

Source§

fn from(problem: Problem) -> Self

Converts to this type from the input type.
Source§

impl From<Problem> for Problems

Source§

fn from(problem: Problem) -> Self

Converts to this type from the input type.
Source§

impl From<Problem> for SerdeProblem

Available on crate feature serde only.
Source§

fn from(problem: Problem) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Problem> for Problems

Source§

fn from_iter<IntoIteratorT>(iterator: IntoIteratorT) -> Self
where IntoIteratorT: IntoIterator<Item = Problem>,

Creates a value from an iterator. Read more
Source§

impl Into<Error> for Problem

Source§

fn into(self) -> Error

Converts this type into the (usually inferred) input type.
Source§

impl<'this> IntoIterator for &'this Problem

Available on crate feature thin-vec only.
Source§

type Item = &'this Cause

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'this, Cause>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'this> IntoIterator for &'this mut Problem

Available on crate feature thin-vec only.
Source§

type Item = &'this mut Cause

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'this, Cause>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Problem

Available on crate feature thin-vec only.
Source§

type Item = Cause

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Cause>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoProblem for Problem

Source§

impl PartialEq for Problem

Source§

fn eq(&self, other: &Problem) -> 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 PartialOrd for Problem

Source§

fn partial_cmp(&self, other: &Problem) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ProblemImplementation for Problem

Available on crate feature thin-vec only.
Source§

fn depth(&self) -> usize

The length of the causation chain.
Source§

fn get(&self, depth: usize) -> Option<&Cause>

A cause in the causation chain.
Source§

fn get_mut(&mut self, depth: usize) -> Option<&mut Cause>

A cause in the causation chain.
Source§

fn top(&self) -> Option<&Cause>

The top of the causation chain.
Source§

fn top_mut(&mut self) -> Option<&mut Cause>

The top of the causation chain.
Source§

fn root(&self) -> Option<&Cause>

The root of the causation chain.
Source§

fn root_mut(&mut self) -> Option<&mut Cause>

The root of the causation chain.
Source§

fn add_top(&mut self, cause: Cause)

Adds to the top of the causation chain.
Source§

fn under(self, problem: Problem) -> Self

Inserts our causation chain under that of the given one.
Source§

fn above(self, problem: Problem) -> Self

Appends our causation chain above that of the given one.
Source§

impl WithExitCode for Problem

Source§

fn with_exit_code<ExitCodeT>(self, exit_code: ExitCodeT) -> Self
where ExitCodeT: Into<ExitCode>,

With an ExitCode attachment.
Source§

fn with_failure_exit_code(self) -> Self

With an ExitCode::FAILURE attachment.
Source§

fn with_success_exit_code(self) -> Self

With an ExitCode::SUCCESS attachment.
Source§

impl Eq for Problem

Source§

impl StructuralPartialEq for Problem

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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<ToStringT> IntoCommonProblem for ToStringT
where ToStringT: ToString,

Source§

fn gloss(self) -> Problem

Into a GlossError problem.
Source§

fn into_thread_problem(self) -> Problem

Into a ThreadError problem.
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.