Move error definition

This commit is contained in:
Wojciech Kozlowski 2024-02-10 19:58:51 +01:00
parent bba2d8e3d7
commit 6b8c7c40fa
2 changed files with 14 additions and 27 deletions

View File

@ -10,7 +10,7 @@ use std::fmt;
#[cfg(test)] #[cfg(test)]
use mockall::automock; use mockall::automock;
use crate::core::collection::Collection; use crate::core::collection::{self, Collection};
/// Trait for interacting with the database. /// Trait for interacting with the database.
#[cfg_attr(test, automock)] #[cfg_attr(test, automock)]
@ -61,6 +61,14 @@ impl From<std::io::Error> for LoadError {
} }
} }
impl From<collection::Error> for LoadError {
fn from(err: collection::Error) -> Self {
match err {
collection::Error::UrlError(e) => LoadError::SerDeError(e),
}
}
}
/// Error type for database calls. /// Error type for database calls.
#[derive(Debug)] #[derive(Debug)]
pub enum SaveError { pub enum SaveError {
@ -111,6 +119,10 @@ mod tests {
assert!(!io_err.to_string().is_empty()); assert!(!io_err.to_string().is_empty());
assert!(!format!("{:?}", io_err).is_empty()); assert!(!format!("{:?}", io_err).is_empty());
let col_err: LoadError = collection::Error::UrlError(String::from("get rekt")).into();
assert!(!col_err.to_string().is_empty());
assert!(!format!("{:?}", col_err).is_empty());
let io_err: SaveError = io::Error::new(io::ErrorKind::Interrupted, "error").into(); let io_err: SaveError = io::Error::new(io::ErrorKind::Interrupted, "error").into();
assert!(!io_err.to_string().is_empty()); assert!(!io_err.to_string().is_empty());
assert!(!format!("{:?}", io_err).is_empty()); assert!(!format!("{:?}", io_err).is_empty());

View File

@ -3,10 +3,7 @@ use std::collections::HashMap;
use serde::Deserialize; use serde::Deserialize;
use crate::{ use crate::{
collection::{ collection::artist::{ArtistId, MusicBrainz},
self,
artist::{ArtistId, MusicBrainz},
},
core::{ core::{
collection::{artist::Artist, Collection}, collection::{artist::Artist, Collection},
database::{serde::Database, LoadError}, database::{serde::Database, LoadError},
@ -49,25 +46,3 @@ impl TryFrom<DeserializeArtist> for Artist {
}) })
} }
} }
impl From<collection::Error> for LoadError {
fn from(err: collection::Error) -> Self {
match err {
collection::Error::UrlError(e) => LoadError::SerDeError(e),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn errors() {
let col_err: LoadError = collection::Error::UrlError(String::from("get rekt")).into();
assert!(!col_err.to_string().is_empty());
assert!(!format!("{:?}", col_err).is_empty());
}
}