Skip to main content

geolith_cli/
cli_error.rs

1//! The error of a `geolith` command.
2
3use geolith_dataset_builder::error::DatasetError;
4use geolith_routing_builder::error::BuildError;
5use geolith_search_builder::SearchError;
6use geolith_tiles_builder::TilesError;
7
8use geolith::error::GeolithError;
9
10/// Why a `geolith` command failed.
11///
12/// The builder errors are boxed: a `Result` of a command stays small.
13///
14/// Each builder reports through its own error type; this enum names the
15/// command that failed and keeps that error as its source, so the whole
16/// chain reaches the terminal (see [`geolith::error::report`]).
17#[derive(Debug, thiserror::Error)]
18#[non_exhaustive]
19pub enum CliError {
20    /// The vector tile, terrain, raster, splat or reconstruction build failed.
21    #[error(transparent)]
22    Tiles(Box<TilesError>),
23
24    /// A `dataset` step failed.
25    #[error(transparent)]
26    Dataset(Box<DatasetError>),
27
28    /// The geocoding build failed.
29    #[error(transparent)]
30    Search(Box<SearchError>),
31
32    /// The routing build failed.
33    #[error(transparent)]
34    Routing(Box<BuildError>),
35
36    /// A command-line value or a reader of the `geolith` library failed.
37    #[error(transparent)]
38    Geolith(Box<GeolithError>),
39
40    /// A flag the command needs is missing or its value is wrong.
41    #[error(transparent)]
42    Usage(#[from] clap::Error),
43
44    /// `--output-format` is not `tiles`, `geocoding` or `routing`.
45    #[error("unsupported --output-format '{format}': expected tiles, geocoding or routing")]
46    UnsupportedFormat {
47        /// The value that was given.
48        format: String,
49    },
50
51    /// A routing build without `--osm-pbf`.
52    #[error("--output-format routing needs --osm-pbf: the graph is built from OSM")]
53    RoutingNeedsOsmPbf,
54}
55
56macro_rules! boxed_from {
57    ($($error:ty => $variant:ident),+ $(,)?) => {$(
58        impl From<$error> for CliError {
59            fn from(error: $error) -> Self {
60                Self::$variant(Box::new(error))
61            }
62        }
63    )+};
64}
65
66boxed_from! {
67    TilesError => Tiles,
68    DatasetError => Dataset,
69    SearchError => Search,
70    BuildError => Routing,
71    GeolithError => Geolith,
72}