1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
use postgres::error::Error as PostgresError; use rusqlite::Error as SqliteError; use std::fmt; use std::io; use toml::de::Error as TomlError; pub type Result<T> = std::result::Result<T, Error>; #[derive(Debug)] pub enum Error { ConfigFileNotFound, BadMigration, Unknown, AdaptorNotFound, IoError(io::Error), TomlError(TomlError), PgError(PostgresError), SqliteError(SqliteError), } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use Error::*; match self { ConfigFileNotFound => write!(f, "`movine.toml` config file not found."), BadMigration => write!(f, "Error parsing migrations."), Unknown => write!(f, "Unknown error occurred"), AdaptorNotFound => write!(f, "Could not find adaptor"), IoError(e) => write!(f, "IO Error: {}", e), TomlError(e) => write!(f, "Unable to read config file: {}", e), PgError(e) => write!(f, "Error in Postgres: {}", e), SqliteError(e) => write!(f, "Error in Sqlite: {}", e), } } } impl From<io::Error> for Error { fn from(error: io::Error) -> Self { Error::IoError(error) } } impl From<TomlError> for Error { fn from(error: TomlError) -> Self { Error::TomlError(error) } } impl From<PostgresError> for Error { fn from(error: PostgresError) -> Self { Error::PgError(error) } } impl From<SqliteError> for Error { fn from(error: SqliteError) -> Self { Error::SqliteError(error) } }