Skip to main content

geolith_search_builder/
error.rs

1//! The error of the geocoding build.
2
3use std::path::PathBuf;
4
5use geolith::error::GeolithError;
6
7/// Why a geocoding build failed.
8///
9/// Each variant names the step that failed. The path involved is a field of
10/// the variant, and the error underneath is its [`source`](std::error::Error::source).
11#[derive(Debug, thiserror::Error)]
12#[non_exhaustive]
13pub enum SearchError {
14    /// A reader or writer of the `geolith` library failed.
15    #[error(transparent)]
16    Geolith(#[from] GeolithError),
17
18    /// A file operation failed.
19    #[error("i/o error")]
20    Io(#[from] std::io::Error),
21
22    /// `--bbox` is not `west,south,east,north`.
23    #[error("invalid --bbox")]
24    InvalidBbox(#[source] GeolithError),
25
26    /// The build area touches Survey of India land and no outline was given.
27    #[error(
28        "the geocoding build area touches Survey of India land (the whole world without \
29         --bbox): pass --india-outline <Survey of India GeoJSON>"
30    )]
31    IndiaOutlineRequired,
32
33    /// `--geocoding-format` names no output format.
34    #[error("unknown geocoding format {format:?}: use glx, pg-copy, photon or pelias")]
35    UnknownFormat {
36        /// What was asked for.
37        format: String,
38    },
39
40    /// The OSM PBF fails while it is read.
41    #[error("OSM PBF read error")]
42    OsmPbf(#[from] osmpbf::Error),
43
44    /// The OSM PBF cannot be opened.
45    #[error("failed to read {}", path.display())]
46    ReadOsmPbf {
47        /// The PBF.
48        path: PathBuf,
49        /// The reader error.
50        #[source]
51        source: osmpbf::Error,
52    },
53
54    /// The output file cannot be created.
55    #[error("failed to create geocoding output: {}", path.display())]
56    CreateOutput {
57        /// The output file.
58        path: PathBuf,
59        /// What the operating system said.
60        #[source]
61        source: std::io::Error,
62    },
63
64    /// The buildings bulk file cannot be created.
65    #[error("failed to create buildings output: {}", path.display())]
66    CreateBuildingsOutput {
67        /// The bulk file.
68        path: PathBuf,
69        /// What the operating system said.
70        #[source]
71        source: std::io::Error,
72    },
73
74    /// The scratch directory of the `.glx` writer cannot be created.
75    #[error("failed to create {}", path.display())]
76    CreateScratch {
77        /// The scratch directory.
78        path: PathBuf,
79        /// What the operating system said.
80        #[source]
81        source: std::io::Error,
82    },
83
84    /// The `--tmpdir` folder (or the system temporary folder) cannot be
85    /// created.
86    #[error("failed to create the temporary folder {} (--tmpdir)", path.display())]
87    CreateTmpDir {
88        /// The directory.
89        path: PathBuf,
90        /// What the operating system said.
91        #[source]
92        source: std::io::Error,
93    },
94
95    /// The dedup bucket files cannot be created.
96    #[error("failed to create dedup buckets in {}", dir.display())]
97    CreateDedupBuckets {
98        /// The directory of the buckets.
99        dir: PathBuf,
100        /// What the operating system said.
101        #[source]
102        source: std::io::Error,
103    },
104
105    /// The OSM dedup cannot start.
106    #[error("failed to start the OSM dedup")]
107    StartDedup(#[source] std::io::Error),
108
109    /// An Overture file cannot be read.
110    #[error("failed to read {}", path.display())]
111    ReadSource {
112        /// The Parquet file.
113        path: PathBuf,
114        /// The reader error.
115        #[source]
116        source: GeolithError,
117    },
118
119    /// A geocoding record cannot be written.
120    #[error("failed to write geocoding record")]
121    WriteRecord(#[source] std::io::Error),
122
123    /// A building document cannot be written.
124    #[error("failed to write building document")]
125    WriteBuildingDocument(#[source] std::io::Error),
126
127    /// The pg-copy writer cannot start.
128    #[error("failed to initialise pg-copy writer")]
129    InitPgCopy(#[source] std::io::Error),
130
131    /// The `.glx` file cannot be finished.
132    #[error("failed to write the glx file")]
133    WriteGlx(#[source] std::io::Error),
134
135    /// The credit cannot be added to the `.glx` file.
136    #[error("failed to add the credit to {}", path.display())]
137    AddCredit {
138        /// The `.glx` file.
139        path: PathBuf,
140        /// What the operating system said.
141        #[source]
142        source: std::io::Error,
143    },
144
145    /// The output file's stem cannot be a SQL identifier. It goes unquoted
146    /// into the DDL, so only letters, digits and `_` (a hyphen becomes `_`) are
147    /// allowed.
148    #[error("the output name {name:?} is not a SQL table name: use letters, digits, '_' and '-'")]
149    InvalidTableName {
150        /// The file stem.
151        name: String,
152    },
153
154    /// The Postgres DDL file cannot be written.
155    #[error("failed to write geocoding DDL: {}", path.display())]
156    WriteDdl {
157        /// The `.sql` file.
158        path: PathBuf,
159        /// What the operating system said.
160        #[source]
161        source: std::io::Error,
162    },
163
164    /// The Wikimedia importance file cannot be opened.
165    #[error("failed to open {}", path.display())]
166    OpenImportance {
167        /// The file.
168        path: PathBuf,
169        /// What the operating system said.
170        #[source]
171        source: std::io::Error,
172    },
173
174    /// The Wikimedia importance file cannot be read.
175    #[error("failed to read {}", path.display())]
176    ReadImportance {
177        /// The file.
178        path: PathBuf,
179        /// What the reader said.
180        #[source]
181        source: std::io::Error,
182    },
183}
184
185/// Result of the geocoding build.
186pub type Result<T, E = SearchError> = std::result::Result<T, E>;