use std::fmt;
#[derive(Debug)]
pub enum GenError {
Config(String),
Introspect(String),
UnmappedType {
column: String,
db_type: String,
},
Unsupported(String),
Io(std::io::Error),
}
impl fmt::Display for GenError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
GenError::Config(msg) => write!(f, "config: {msg}"),
GenError::Introspect(msg) => write!(f, "introspection: {msg}"),
GenError::UnmappedType { column, db_type } => write!(
f,
"no type mapping for {column} (db type `{db_type}`); \
add a [types.map] or [[types.override]] entry"
),
GenError::Unsupported(msg) => write!(f, "unsupported: {msg}"),
GenError::Io(e) => write!(f, "io: {e}"),
}
}
}
impl std::error::Error for GenError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
GenError::Io(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for GenError {
fn from(e: std::io::Error) -> Self {
GenError::Io(e)
}
}
pub type Result<T> = std::result::Result<T, GenError>;