geolith-cli 0.3.2

Rust vector tile generator — OSM + Overture Maps → protomaps PMTiles
Documentation
//! The error of a `geolith` command.

use geolith_dataset_builder::error::DatasetError;
use geolith_routing_builder::error::BuildError;
use geolith_search_builder::SearchError;
use geolith_tiles_builder::TilesError;

use geolith::error::GeolithError;

/// Why a `geolith` command failed.
///
/// The builder errors are boxed: a `Result` of a command stays small.
///
/// Each builder reports through its own error type; this enum names the
/// command that failed and keeps that error as its source, so the whole
/// chain reaches the terminal (see [`geolith::error::report`]).
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum CliError {
    /// The vector tile, terrain, raster, splat or reconstruction build failed.
    #[error(transparent)]
    Tiles(Box<TilesError>),

    /// A `dataset` step failed.
    #[error(transparent)]
    Dataset(Box<DatasetError>),

    /// The geocoding build failed.
    #[error(transparent)]
    Search(Box<SearchError>),

    /// The routing build failed.
    #[error(transparent)]
    Routing(Box<BuildError>),

    /// A command-line value or a reader of the `geolith` library failed.
    #[error(transparent)]
    Geolith(Box<GeolithError>),

    /// A flag the command needs is missing or its value is wrong.
    #[error(transparent)]
    Usage(#[from] clap::Error),

    /// `--output-format` is not `tiles`, `geocoding` or `routing`.
    #[error("unsupported --output-format '{format}': expected tiles, geocoding or routing")]
    UnsupportedFormat {
        /// The value that was given.
        format: String,
    },

    /// A routing build without `--osm-pbf`.
    #[error("--output-format routing needs --osm-pbf: the graph is built from OSM")]
    RoutingNeedsOsmPbf,
}

macro_rules! boxed_from {
    ($($error:ty => $variant:ident),+ $(,)?) => {$(
        impl From<$error> for CliError {
            fn from(error: $error) -> Self {
                Self::$variant(Box::new(error))
            }
        }
    )+};
}

boxed_from! {
    TilesError => Tiles,
    DatasetError => Dataset,
    SearchError => Search,
    BuildError => Routing,
    GeolithError => Geolith,
}