1use std::fmt;
2
3#[derive(Debug)]
7pub enum GenError {
8 Config(String),
10 Introspect(String),
12 UnmappedType {
15 column: String,
17 db_type: String,
19 },
20 Unsupported(String),
23 Io(std::io::Error),
25}
26
27impl fmt::Display for GenError {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match self {
30 GenError::Config(msg) => write!(f, "config: {msg}"),
31 GenError::Introspect(msg) => write!(f, "introspection: {msg}"),
32 GenError::UnmappedType { column, db_type } => write!(
33 f,
34 "no type mapping for {column} (db type `{db_type}`); \
35 add a [types.map] or [[types.override]] entry"
36 ),
37 GenError::Unsupported(msg) => write!(f, "unsupported: {msg}"),
38 GenError::Io(e) => write!(f, "io: {e}"),
39 }
40 }
41}
42
43impl std::error::Error for GenError {
44 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
45 match self {
46 GenError::Io(e) => Some(e),
47 _ => None,
48 }
49 }
50}
51
52impl From<std::io::Error> for GenError {
53 fn from(e: std::io::Error) -> Self {
54 GenError::Io(e)
55 }
56}
57
58pub type Result<T> = std::result::Result<T, GenError>;