martin_core/tiles/postgres/
errors.rs

1//! Error types for `PostgreSQL` operations.
2
3use std::io;
4use std::path::PathBuf;
5
6use deadpool_postgres::tokio_postgres::Error as TokioPostgresError;
7use deadpool_postgres::{BuildError, PoolError};
8use martin_tile_utils::TileCoord;
9use semver::Version;
10
11use crate::tiles::UrlQuery;
12use crate::tiles::postgres::utils::query_to_json;
13
14/// Result type for `PostgreSQL` operations.
15pub type PostgresResult<T> = Result<T, PostgresError>;
16
17/// Errors that can occur when working with `PostgreSQL` databases.
18#[non_exhaustive]
19#[derive(thiserror::Error, Debug)]
20pub enum PostgresError {
21    /// Cannot load platform root certificates.
22    #[error("Cannot load platform root certificates: {0:?}")]
23    CannotLoadRoots(Vec<rustls_native_certs::Error>),
24
25    /// Cannot open SSL certificate file.
26    #[error("Cannot open certificate file {1}: {0}")]
27    CannotOpenCert(#[source] io::Error, PathBuf),
28
29    /// Cannot parse SSL certificate file.
30    #[error("Cannot parse certificate file {1}: {0}")]
31    CannotParseCert(#[source] io::Error, PathBuf),
32
33    /// Invalid PEM RSA private key file.
34    #[error("Unable to parse PEM RSA key file {0}")]
35    InvalidPrivateKey(PathBuf),
36
37    /// Cannot use client certificate pair.
38    #[error("Unable to use client certificate pair {1} / {2}: {0}")]
39    CannotUseClientKey(#[source] rustls::Error, PathBuf, PathBuf),
40
41    /// Wrapper for rustls errors.
42    #[error(transparent)]
43    RustlsError(#[from] rustls::Error),
44
45    /// Unknown SSL mode specified.
46    #[error("Unknown SSL mode: {0:?}")]
47    UnknownSslMode(deadpool_postgres::tokio_postgres::config::SslMode),
48
49    /// `PostgreSQL` database error.
50    #[error("Postgres error while {1}: {0}")]
51    PostgresError(#[source] TokioPostgresError, &'static str),
52
53    /// Cannot build `PostgreSQL` connection pool.
54    #[error("Unable to build a Postgres connection pool {1}: {0}")]
55    PostgresPoolBuildError(#[source] BuildError, String),
56
57    /// Cannot get connection from `PostgreSQL` pool.
58    #[error("Unable to get a Postgres connection from the pool {1}: {0}")]
59    PostgresPoolConnError(#[source] PoolError, String),
60
61    /// Invalid `PostgreSQL` connection string.
62    #[error("Unable to parse connection string {1}: {0}")]
63    BadConnectionString(#[source] TokioPostgresError, String),
64
65    /// Cannot parse `PostGIS` version.
66    #[error("Unable to parse PostGIS version {1}: {0}")]
67    BadPostgisVersion(#[source] semver::Error, String),
68
69    /// Cannot parse `PostgreSQL` version.
70    #[error("Unable to parse PostgreSQL version {1}: {0}")]
71    BadPostgresVersion(#[source] semver::Error, String),
72
73    /// `PostGIS` version too old.
74    #[error("PostGIS version {0} is too old, minimum required is {1}")]
75    PostgisTooOld(Version, Version),
76
77    /// `PostgreSQL` version too old.
78    #[error("PostgreSQL version {0} is too old, minimum required is {1}")]
79    PostgresqlTooOld(Version, Version),
80
81    /// Invalid table extent configuration.
82    #[error("Invalid extent setting in source {0} for table {1}: extent=0")]
83    InvalidTableExtent(String, String),
84
85    /// Query preparation error.
86    #[error("Error preparing a query for the tile '{1}' ({2}): {3} {0}")]
87    PrepareQueryError(#[source] TokioPostgresError, String, String, String),
88
89    /// Tile retrieval error.
90    #[error(r"Unable to get tile {2:#} from {1}: {0}")]
91    GetTileError(#[source] TokioPostgresError, String, TileCoord),
92
93    /// Tile retrieval error with query parameters.
94    #[error(r"Unable to get tile {2:#} with {json_query:?} params from {1}: {0}", json_query=query_to_json(.3.as_ref()))]
95    GetTileWithQueryError(
96        #[source] TokioPostgresError,
97        String,
98        TileCoord,
99        Option<UrlQuery>,
100    ),
101}