martin-core 0.12.1

Basic building blocks of MapLibre's Martin tile server.
Documentation
#[cfg(feature = "unstable-cog")]
use super::cog::CogError;
#[cfg(feature = "unstable-duckdb")]
use super::duckdb::DuckDBError;
#[cfg(feature = "hillshade")]
use super::hillshade::HillshadeError;
#[cfg(feature = "mbtiles")]
use super::mbtiles::MbtilesError;
#[cfg(feature = "passthrough")]
use super::passthrough::PassthroughError;
#[cfg(feature = "pmtiles")]
use super::pmtiles::PmtilesError;
#[cfg(feature = "postgres")]
use super::postgres::PostgresError;

/// Errors that can occur during tile processing operations.
#[non_exhaustive]
#[derive(thiserror::Error, Debug)]
pub enum MartinCoreError {
    /// Errors that can occur during [`mbtiles`](crate::tiles::cog) processing operations.
    #[cfg(feature = "mbtiles")]
    #[error(transparent)]
    MbtilesError(#[from] MbtilesError),

    /// Errors that can occur during [`postgres`](crate::tiles::cog) processing operations.
    #[cfg(feature = "postgres")]
    #[error(transparent)]
    PostgresError(#[from] PostgresError),

    /// Errors that can occur during [`duckdb`](crate::tiles::duckdb) processing operations.
    #[cfg(feature = "unstable-duckdb")]
    #[error(transparent)]
    DuckDBError(#[from] DuckDBError),

    /// Errors that can occur during [`pmtiles`](crate::tiles::cog) processing operations.
    #[cfg(feature = "pmtiles")]
    #[error(transparent)]
    PmtilesError(#[from] PmtilesError),

    /// Errors that can occur during [`passthrough`](crate::tiles::passthrough) processing operations.
    #[cfg(feature = "passthrough")]
    #[error(transparent)]
    PassthroughError(#[from] PassthroughError),

    /// Errors that can occur during [`cog`](crate::tiles::cog) processing operations.
    #[cfg(feature = "unstable-cog")]
    #[error(transparent)]
    CogError(#[from] CogError),

    /// Errors that can occur while baking a [`hillshade`](crate::tiles::hillshade).
    #[cfg(feature = "hillshade")]
    #[error(transparent)]
    HillshadeError(#[from] HillshadeError),

    /// The tile source was modified since it was opened and must be reloaded before retrying.
    ///
    /// Use of this error REQUIRES the `Source` to also implement `Source::try_reload()`.
    #[error("Source was modified and needs to be reloaded")]
    SourceNeedsReload,

    /// Errors that can occur during [`geojson`](crate::tiles::geojson) processing operations.
    #[cfg(feature = "geojson")]
    #[error(transparent)]
    GeoJsonError(#[from] super::geojson::GeoJsonError),

    /// Errors occurring from other sources, not implemented by `martin-core`.
    #[error(transparent)]
    OtherError(#[from] Box<dyn std::error::Error + Send + Sync>),
}

/// A convenience [`Result`] for tiles coming from `martin-core`.
pub type MartinCoreResult<T> = Result<T, MartinCoreError>;

impl crate::Classify for MartinCoreError {
    fn kind(&self) -> crate::ErrorKind {
        match self {
            #[cfg(feature = "mbtiles")]
            Self::MbtilesError(e) => e.kind(),
            #[cfg(feature = "postgres")]
            Self::PostgresError(e) => e.kind(),
            #[cfg(feature = "unstable-duckdb")]
            Self::DuckDBError(e) => e.kind(),
            #[cfg(feature = "pmtiles")]
            Self::PmtilesError(e) => e.kind(),
            #[cfg(feature = "passthrough")]
            Self::PassthroughError(e) => e.kind(),
            #[cfg(feature = "unstable-cog")]
            Self::CogError(e) => e.kind(),
            #[cfg(feature = "geojson")]
            Self::GeoJsonError(e) => e.kind(),
            #[cfg(feature = "hillshade")]
            Self::HillshadeError(e) => e.kind(),
            Self::SourceNeedsReload | Self::OtherError(_) => crate::ErrorKind::Internal,
        }
    }
}