summaryrefslogtreecommitdiffstats
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index d25b7a7..f22f331 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,3 +1,4 @@
+//! Module contains all custom errors introduced by this crate.
use std::fmt::{self, Display, Debug};
use std::mem::drop;
@@ -25,6 +26,12 @@ error cases:
*/
+/// Extension adding a `with_source` method to anything implementing `Fail`.
+///
+/// This provides a uniform way to combine a error with the source which
+/// caused the error and return them together. The returned `WithSource`
+/// instance will implement `Fail` if possible but does not require it,
+/// making it compatible with non 'static, Send, Sync sources.
pub trait WithSourceExt: Sized + Fail {
fn with_source<S>(self, source: S) -> WithSource<Self, S>
where S: Debug
@@ -52,29 +59,36 @@ impl<E, S> WithSource<E, S>
where E: Fail, S: Debug
{
+ /// Create a new instance given an error and it's source.
pub fn new(error: E, source: S) -> Self {
WithSource { error, source }
}
+
+ /// Return a reference to it's source.
pub fn source(&self) -> &S {
&self.source
}
+ /// Return a reference to the contained error.
pub fn error(&self) -> &E {
&self.error
}
+ /// Turns this type into it's source.
pub fn into_source(self) -> S {
let WithSource { error, source } = self;
drop(error);
source
}
+ /// Turns this type into it's error.
pub fn into_error(self) -> E {
let WithSource { error, source } = self;
drop(source);
error
}
+ /// Decomposes this type into its error and its source.
pub fn split(self) -> (E, S) {
let WithSource { error, source } = self;
(error, source)
@@ -101,11 +115,15 @@ impl<E, S> Display for WithSource<E, S>
}
}
+/// Error returned when composing a `Mail` failed.
#[derive(Debug, Fail)]
pub enum CompositionError<TE: Fail> {
+ /// It failed to use the underlying template engine.
#[fail(display = "{}", _0)]
Template(TE),
+ /// It didn't fail to get all `MailParts` but wasn't
+ /// able to compose them into an mail.
#[fail(display = "{}", _0)]
Builder(ExtendedBuilderError)
}
@@ -126,17 +144,24 @@ impl<FT, TE> From<FT> for CompositionError<TE>
// }
// }
+/// Kinds of Error which can be caused by the builder extension.
+///
+/// (The builder extension is a trait providing additional methods
+/// to the `MailBuilder`)
#[derive(Copy, Clone, Debug, Fail, PartialEq, Eq, Hash)]
pub enum ExtendedBuilderErrorKind {
#[fail(display="need embedding to create a body with an embedding")]
EmbeddingMissing,
}
+/// Error returned if building the mail failed.
#[derive(Debug, Fail)]
pub enum ExtendedBuilderError {
+ /// A error covered by `BuilderError` occurred.
#[fail(display = "{}", _0)]
Normal(BuilderError),
+ /// An error not covered by `BuilderError` occurred.
#[fail(display = "{}", _0)]
Extended(Context<ExtendedBuilderErrorKind>)
@@ -182,27 +207,35 @@ impl From<ComponentCreationError> for ExtendedBuilderError {
}
}
+/// Error kinds associated with creating `MailSendData`
#[derive(Copy, Clone, Debug, Fail, PartialEq, Eq, Hash)]
pub enum MailSendDataErrorKind {
+ /// No `From` was set.
#[fail(display = "missing data for From field")]
MissingFrom,
+ /// No `To` was set.
#[fail(display = "missing data for To field")]
MissingTo,
+ /// No `Subject` was set.
#[fail(display = "missing data for Subject field")]
MissingSubject,
+ /// No `TemplateId` was given.
#[fail(display = "missing template id")]
MissingTemplateId,
+ /// No `TemplateData` was given.
#[fail(display = "missing template data")]
MissingTemplateData,
+ /// No `Sender` was given in an situation where it's needed.
#[fail(display = "multiple mailboxes in from field but no sender field")]
MultiFromButNoSender
}
+/// Error returned when building `MailSendData` with the `MailSendDataBuilder` failed.
#[derive(Debug)]
pub struct MailSendDataError {
inner: Context<MailSendDataErrorKind>,