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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//!
//! Errors
//!
use std::error::Error;

use std::fmt;
use std::fmt::Formatter;
use thiserror::Error;

///
/// PgEmbed errors
#[derive(Error, Debug)]
pub struct PgEmbedError {
    pub error_type: PgEmbedErrorType,
    pub source: Option<Box<dyn Error + Send>>,
    pub message: Option<String>,
}

impl fmt::Display for PgEmbedError {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "error_type: {:?}\nsource: \n{:?}\nmessage: \n{:?}\n",
            self.error_type, self.source, self.message
        )
    }
}

///
/// Common pg_embed errors, independent from features used
///
#[derive(Debug, PartialEq)]
pub enum PgEmbedErrorType {
    /// Invalid postgresql binaries download url
    InvalidPgUrl,
    /// Invalid postgresql binaries package
    InvalidPgPackage,
    /// Could not write file
    WriteFileError,
    /// Could not read file
    ReadFileError,
    /// Could not create directory
    DirCreationError,
    /// Failed to unpack postgresql binaries
    UnpackFailure,
    /// Postgresql could not be started
    PgStartFailure,
    /// Postgresql could not be stopped
    PgStopFailure,
    /// Postgresql could not be initialized
    PgInitFailure,
    /// Clean up error
    PgCleanUpFailure,
    /// Purging error
    PgPurgeFailure,
    /// Buffer read error
    PgBufferReadError,
    /// Lock error
    PgLockError,
    /// Child process error
    PgProcessError,
    /// Timed out error
    PgTimedOutError,
    /// Task join error
    PgTaskJoinError,
    /// Error wrapper
    PgError,
    /// Postgresql binaries download failure
    DownloadFailure,
    /// Request response bytes convertion failure
    ConversionFailure,
    /// Channel send error
    SendFailure,
    /// sqlx query error
    SqlQueryError,
    /// migration error
    MigrationError,
}