-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,20 @@ | ||
//! Error types, which can be emited by sanitization procedure. | ||
//! Errors, which can be emited by sanitization procedure. | ||
|
||
use std::error::Error; | ||
use std::fmt; | ||
|
||
/// Sanitization error | ||
#[derive(Debug)] | ||
pub enum SanitizeError { | ||
/// UTF-8 decoding error | ||
StrUtf8Error(std::str::Utf8Error), | ||
|
||
/// UTF-8 decoding error | ||
Utf8Error(std::string::FromUtf8Error), | ||
|
||
/// Serialization error | ||
SerializeError(std::io::Error), | ||
} | ||
pub struct SanitizeError(pub(crate) Box<dyn Error>); | ||
|
||
impl fmt::Display for SanitizeError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
SanitizeError::StrUtf8Error(e) => write!(f, "UTF-8 decode error {}", e), | ||
SanitizeError::Utf8Error(e) => write!(f, "UTF-8 decode error {}", e), | ||
SanitizeError::SerializeError(e) => write!(f, "Serialization error {}", e), | ||
} | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
impl Error for SanitizeError { | ||
fn source(&self) -> Option<&(dyn Error + 'static)> { | ||
match self { | ||
SanitizeError::StrUtf8Error(e) => Some(e), | ||
SanitizeError::Utf8Error(e) => Some(e), | ||
SanitizeError::SerializeError(e) => Some(e), | ||
} | ||
self.0.source() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters