martin_core/tiles/postgres/
errors.rs1use 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
14pub type PostgresResult<T> = Result<T, PostgresError>;
16
17#[non_exhaustive]
19#[derive(thiserror::Error, Debug)]
20pub enum PostgresError {
21 #[error("Cannot load platform root certificates: {0:?}")]
23 CannotLoadRoots(Vec<rustls_native_certs::Error>),
24
25 #[error("Cannot open certificate file {1}: {0}")]
27 CannotOpenCert(#[source] io::Error, PathBuf),
28
29 #[error("Cannot parse certificate file {1}: {0}")]
31 CannotParseCert(#[source] io::Error, PathBuf),
32
33 #[error("Unable to parse PEM RSA key file {0}")]
35 InvalidPrivateKey(PathBuf),
36
37 #[error("Unable to use client certificate pair {1} / {2}: {0}")]
39 CannotUseClientKey(#[source] rustls::Error, PathBuf, PathBuf),
40
41 #[error(transparent)]
43 RustlsError(#[from] rustls::Error),
44
45 #[error("Unknown SSL mode: {0:?}")]
47 UnknownSslMode(deadpool_postgres::tokio_postgres::config::SslMode),
48
49 #[error("Postgres error while {1}: {0}")]
51 PostgresError(#[source] TokioPostgresError, &'static str),
52
53 #[error("Unable to build a Postgres connection pool {1}: {0}")]
55 PostgresPoolBuildError(#[source] BuildError, String),
56
57 #[error("Unable to get a Postgres connection from the pool {1}: {0}")]
59 PostgresPoolConnError(#[source] PoolError, String),
60
61 #[error("Unable to parse connection string {1}: {0}")]
63 BadConnectionString(#[source] TokioPostgresError, String),
64
65 #[error("Unable to parse PostGIS version {1}: {0}")]
67 BadPostgisVersion(#[source] semver::Error, String),
68
69 #[error("Unable to parse PostgreSQL version {1}: {0}")]
71 BadPostgresVersion(#[source] semver::Error, String),
72
73 #[error("PostGIS version {0} is too old, minimum required is {1}")]
75 PostgisTooOld(Version, Version),
76
77 #[error("PostgreSQL version {0} is too old, minimum required is {1}")]
79 PostgresqlTooOld(Version, Version),
80
81 #[error("Invalid extent setting in source {0} for table {1}: extent=0")]
83 InvalidTableExtent(String, String),
84
85 #[error("Error preparing a query for the tile '{1}' ({2}): {3} {0}")]
87 PrepareQueryError(#[source] TokioPostgresError, String, String, String),
88
89 #[error(r"Unable to get tile {2:#} from {1}: {0}")]
91 GetTileError(#[source] TokioPostgresError, String, TileCoord),
92
93 #[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}