Skip to content

Commit

Permalink
[db] Add conversion from FromUtf8Error to DbError #223 (#224)
Browse files Browse the repository at this point in the history
* Update db_error.rs

* Update db_error.rs
  • Loading branch information
michaelvlach authored Sep 18, 2022
1 parent aa938d4 commit 97702a0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/db_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[allow(dead_code)]
#[derive(Debug)]
pub struct DbError {
pub description: String,
Expand Down Expand Up @@ -29,6 +28,13 @@ impl From<std::io::Error> for DbError {
}
}

impl From<std::string::FromUtf8Error> for DbError {
#[track_caller]
fn from(error: std::string::FromUtf8Error) -> Self {
DbError::from(error.to_string())
}
}

impl From<&str> for DbError {
#[track_caller]
fn from(description: &str) -> Self {
Expand Down Expand Up @@ -118,6 +124,11 @@ mod tests {
let _error = DbError::from(std::io::Error::from(std::io::ErrorKind::NotFound));
}

#[test]
fn from_utf8_error() {
let _error = DbError::from(String::from_utf8(vec![0xdf, 0xff]).unwrap_err());
}

#[test]
fn source() {
let file = file!();
Expand Down

0 comments on commit 97702a0

Please sign in to comment.