diff --git a/martin/src/pg/config.rs b/martin/src/pg/config.rs index 39ad64d9c..b25f5e7ec 100644 --- a/martin/src/pg/config.rs +++ b/martin/src/pg/config.rs @@ -12,6 +12,7 @@ use crate::pg::builder::PgBuilder; use crate::pg::config_function::FuncInfoSources; use crate::pg::config_table::TableInfoSources; use crate::pg::utils::on_slow; +use crate::pg::PgError; use crate::pg::PgResult; use crate::source::TileInfoSources; use crate::utils::{IdResolver, OptBoolObj, OptOneMany}; @@ -94,6 +95,23 @@ pub struct PgCfgPublishFuncs { impl PgConfig { /// Apply defaults to the config, and validate if there is a connection string + pub fn validate(&self) -> PgResult<()> { + if let Some(pool_size) = self.pool_size { + if pool_size < 1 { + return Err(PgError::ConfigError( + "pool_size must be greater than or equal to 1.", + )); + } + } + if self.connection_string.is_none() { + return Err(PgError::ConfigError( + "A connection string must be provided.", + )); + } + + Ok(()) + } + pub fn finalize(&mut self) -> PgResult { let mut res = UnrecognizedValues::new(); if let Some(ref ts) = self.tables { @@ -110,6 +128,7 @@ impl PgConfig { self.auto_publish = OptBoolObj::Bool(true); } + self.validate()?; Ok(res) } diff --git a/martin/src/pg/errors.rs b/martin/src/pg/errors.rs index b8b995ccb..d4220274f 100644 --- a/martin/src/pg/errors.rs +++ b/martin/src/pg/errors.rs @@ -69,4 +69,7 @@ pub enum PgError { #[error(r#"Unable to get tile {2:#} with {:?} params from {1}: {0}"#, query_to_json(.3.as_ref()))] GetTileWithQueryError(#[source] TokioPgError, String, TileCoord, Option), + + #[error("Configuration error: {0}")] + ConfigError(&'static str), }