Skip to main content

elephantry/
errors.rs

1pub type Result<T = ()> = std::result::Result<T, crate::Error>;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5    /** An error in async context. */
6    #[error("Async error: {0}")]
7    Async(libpq::errors::Error),
8    /** Chrono error */
9    #[cfg(feature = "chrono")]
10    #[error("{0}")]
11    Chrono(String),
12    /** Configuration error */
13    #[cfg(feature = "config")]
14    #[error(transparent)]
15    Config(#[from] config::ConfigError),
16    /** Connection error */
17    #[error("{error}")]
18    Connect {
19        dsn: String,
20        error: libpq::errors::Error,
21    },
22    /** Copy error */
23    #[error("Copy error: {0}")]
24    Copy(libpq::errors::Error),
25    /** Escaping error */
26    #[error("Unable to escape '{0}': {1}")]
27    Escape(String, libpq::errors::Error),
28    #[error("{0}")]
29    Environment(#[from] envir::Error),
30    /** Unable to transform a SQL field in rust value */
31    #[error("Unable to convert from SQL {} (oid={}) to {rust_type}: {value}. Try {}", pg_type.name, pg_type.oid, crate::pq::sql_to_rust(pg_type))]
32    FromSql {
33        pg_type: crate::pq::Type,
34        rust_type: String,
35        value: String,
36    },
37    #[error("{0}")]
38    Infallible(#[from] std::convert::Infallible),
39    /** Inspector error */
40    #[error("{0}")]
41    Inspect(String),
42    /** Input/Output error */
43    #[error(transparent)]
44    Io(#[from] std::io::Error),
45    /** Jiff error */
46    #[cfg(feature = "jiff")]
47    #[error("{0}")]
48    Jiff(#[from] jiff::Error),
49    #[error("{0}")]
50    Libpq(#[from] libpq::errors::Error),
51    /** Our result set require an extra field to build the entity */
52    #[error("Missing field {0}")]
53    MissingField(String),
54    /** Connection mutex poisoned */
55    #[error("Mutex error: {0}")]
56    Mutex(String),
57    /** Fetch a null value in a non-option type */
58    #[error("Try to retreive null field as non-option type")]
59    NotNull,
60    /** Parse error */
61    #[error("{0}")]
62    Parse(String),
63    /** Parse bool error */
64    #[error(transparent)]
65    ParseBoolError(#[from] std::str::ParseBoolError),
66    /** Parse int error */
67    #[error(transparent)]
68    ParseIntError(#[from] std::num::ParseIntError),
69    /** Ping error */
70    #[error("Ping error: {0:?}")]
71    Ping(crate::connection::PingStatus),
72    /** Incomplete primary key */
73    #[error("Invalid primary key")]
74    PrimaryKey,
75    /** SQL error */
76    #[error("{}", .0.error_message().unwrap().unwrap_or_else(|| "Unknow SQL error".to_string()))]
77    Sql(crate::pq::Result),
78    /** Unable to transform a rust value to SQL */
79    #[error("Invalid convertion from {} to {rust_type}: {message}", .pg_type.name)]
80    ToSql {
81        pg_type: crate::pq::Type,
82        rust_type: String,
83        message: String,
84    },
85    /** TryFrom int error */
86    #[error(transparent)]
87    TryFromIntError(#[from] std::num::TryFromIntError),
88    /** UTF8 error */
89    #[error(transparent)]
90    Utf8(#[from] std::string::FromUtf8Error),
91    /** XML error */
92    #[cfg(feature = "xml")]
93    #[error(transparent)]
94    Xml(#[from] xmltree::Error),
95}