Skip to main content

osmflow_sync/
error.rs

1use std::io;
2use std::path::{Path, PathBuf};
3
4use osmflow::PbfError;
5use osmflow::nodes::NodeStoreError;
6use osmflow::osc::OscError;
7
8/// An error of an import, an update or a rebuild.
9#[derive(Debug, thiserror::Error)]
10pub enum SyncError {
11    /// A query failed, or the database could not be reached.
12    #[error("database: {0}")]
13    Db(#[from] postgres::Error),
14    /// Reading the PBF file failed.
15    #[error(transparent)]
16    Pbf(#[from] PbfError),
17    /// Reading a replication diff or state failed.
18    #[error(transparent)]
19    Osc(#[from] OscError),
20    /// The node file failed.
21    #[error(transparent)]
22    Nodes(#[from] NodeStoreError),
23    /// The reverse index failed.
24    #[error("{path}: {source}", path = .path.display())]
25    Index {
26        /// The index file.
27        path: PathBuf,
28        /// What failed.
29        source: redb::Error,
30    },
31    /// A file is missing: the node file or the reverse index, which `rebuild` makes again.
32    #[error("{path} does not exist; `rebuild` makes it from the database", path = .0.display())]
33    Missing(PathBuf),
34    /// Another I/O error.
35    #[error(transparent)]
36    Io(#[from] io::Error),
37    /// The connection string's `sslmode` or `sslrootcert` cannot be used.
38    #[error(transparent)]
39    Tls(#[from] crate::TlsError),
40    /// The database, its files and the input do not fit together, as the message says.
41    #[error("{0}")]
42    State(String),
43}
44
45impl SyncError {
46    pub(crate) fn index(path: &Path, source: redb::Error) -> Self {
47        Self::Index {
48            path: path.to_path_buf(),
49            source,
50        }
51    }
52
53    pub(crate) fn state(msg: impl Into<String>) -> Self {
54        Self::State(msg.into())
55    }
56}