pg_embed/
pg_errors.rs

1//!
2//! Errors
3//!
4use std::error::Error;
5
6use std::fmt;
7use std::fmt::Formatter;
8use thiserror::Error;
9
10///
11/// PgEmbed errors
12#[derive(Error, Debug)]
13pub struct PgEmbedError {
14    pub error_type: PgEmbedErrorType,
15    pub source: Option<Box<dyn Error + Sync + Send>>,
16    pub message: Option<String>,
17}
18
19impl fmt::Display for PgEmbedError {
20    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
21        write!(
22            f,
23            "error_type: {:?}\nsource: \n{:?}\nmessage: \n{:?}\n",
24            self.error_type, self.source, self.message
25        )
26    }
27}
28
29///
30/// Common pg_embed errors, independent from features used
31///
32#[derive(Debug, PartialEq)]
33pub enum PgEmbedErrorType {
34    /// Invalid postgresql binaries download url
35    InvalidPgUrl,
36    /// Invalid postgresql binaries package
37    InvalidPgPackage,
38    /// Could not write file
39    WriteFileError,
40    /// Could not read file
41    ReadFileError,
42    /// Could not create directory
43    DirCreationError,
44    /// Failed to unpack postgresql binaries
45    UnpackFailure,
46    /// Postgresql could not be started
47    PgStartFailure,
48    /// Postgresql could not be stopped
49    PgStopFailure,
50    /// Postgresql could not be initialized
51    PgInitFailure,
52    /// Clean up error
53    PgCleanUpFailure,
54    /// Purging error
55    PgPurgeFailure,
56    /// Buffer read error
57    PgBufferReadError,
58    /// Lock error
59    PgLockError,
60    /// Child process error
61    PgProcessError,
62    /// Timed out error
63    PgTimedOutError,
64    /// Task join error
65    PgTaskJoinError,
66    /// Error wrapper
67    PgError,
68    /// Postgresql binaries download failure
69    DownloadFailure,
70    /// Request response bytes convertion failure
71    ConversionFailure,
72    /// Channel send error
73    SendFailure,
74    /// sqlx query error
75    SqlQueryError,
76    /// migration error
77    MigrationError,
78}