geolith-search-builder 0.3.2

Builds geocoding indexes from Overture Maps and OpenStreetMap: Postgres COPY files, Photon and Pelias bulk files, and the search part of a .glx file
Documentation
//! The error of the geocoding build.

use std::path::PathBuf;

use geolith::error::GeolithError;

/// Why a geocoding build failed.
///
/// Each variant names the step that failed. The path involved is a field of
/// the variant, and the error underneath is its [`source`](std::error::Error::source).
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SearchError {
    /// A reader or writer of the `geolith` library failed.
    #[error(transparent)]
    Geolith(#[from] GeolithError),

    /// A file operation failed.
    #[error("i/o error")]
    Io(#[from] std::io::Error),

    /// `--bbox` is not `west,south,east,north`.
    #[error("invalid --bbox")]
    InvalidBbox(#[source] GeolithError),

    /// The build area touches Survey of India land and no outline was given.
    #[error(
        "the geocoding build area touches Survey of India land (the whole world without \
         --bbox): pass --india-outline <Survey of India GeoJSON>"
    )]
    IndiaOutlineRequired,

    /// `--geocoding-format` names no output format.
    #[error("unknown geocoding format {format:?}: use glx, pg-copy, photon or pelias")]
    UnknownFormat {
        /// What was asked for.
        format: String,
    },

    /// The OSM PBF fails while it is read.
    #[error("OSM PBF read error")]
    OsmPbf(#[from] osmpbf::Error),

    /// The OSM PBF cannot be opened.
    #[error("failed to read {}", path.display())]
    ReadOsmPbf {
        /// The PBF.
        path: PathBuf,
        /// The reader error.
        #[source]
        source: osmpbf::Error,
    },

    /// The output file cannot be created.
    #[error("failed to create geocoding output: {}", path.display())]
    CreateOutput {
        /// The output file.
        path: PathBuf,
        /// What the operating system said.
        #[source]
        source: std::io::Error,
    },

    /// The buildings bulk file cannot be created.
    #[error("failed to create buildings output: {}", path.display())]
    CreateBuildingsOutput {
        /// The bulk file.
        path: PathBuf,
        /// What the operating system said.
        #[source]
        source: std::io::Error,
    },

    /// The scratch directory of the `.glx` writer cannot be created.
    #[error("failed to create {}", path.display())]
    CreateScratch {
        /// The scratch directory.
        path: PathBuf,
        /// What the operating system said.
        #[source]
        source: std::io::Error,
    },

    /// The `--tmpdir` folder (or the system temporary folder) cannot be
    /// created.
    #[error("failed to create the temporary folder {} (--tmpdir)", path.display())]
    CreateTmpDir {
        /// The directory.
        path: PathBuf,
        /// What the operating system said.
        #[source]
        source: std::io::Error,
    },

    /// The dedup bucket files cannot be created.
    #[error("failed to create dedup buckets in {}", dir.display())]
    CreateDedupBuckets {
        /// The directory of the buckets.
        dir: PathBuf,
        /// What the operating system said.
        #[source]
        source: std::io::Error,
    },

    /// The OSM dedup cannot start.
    #[error("failed to start the OSM dedup")]
    StartDedup(#[source] std::io::Error),

    /// An Overture file cannot be read.
    #[error("failed to read {}", path.display())]
    ReadSource {
        /// The Parquet file.
        path: PathBuf,
        /// The reader error.
        #[source]
        source: GeolithError,
    },

    /// A geocoding record cannot be written.
    #[error("failed to write geocoding record")]
    WriteRecord(#[source] std::io::Error),

    /// A building document cannot be written.
    #[error("failed to write building document")]
    WriteBuildingDocument(#[source] std::io::Error),

    /// The pg-copy writer cannot start.
    #[error("failed to initialise pg-copy writer")]
    InitPgCopy(#[source] std::io::Error),

    /// The `.glx` file cannot be finished.
    #[error("failed to write the glx file")]
    WriteGlx(#[source] std::io::Error),

    /// The credit cannot be added to the `.glx` file.
    #[error("failed to add the credit to {}", path.display())]
    AddCredit {
        /// The `.glx` file.
        path: PathBuf,
        /// What the operating system said.
        #[source]
        source: std::io::Error,
    },

    /// The output file's stem cannot be a SQL identifier. It goes unquoted
    /// into the DDL, so only letters, digits and `_` (a hyphen becomes `_`) are
    /// allowed.
    #[error("the output name {name:?} is not a SQL table name: use letters, digits, '_' and '-'")]
    InvalidTableName {
        /// The file stem.
        name: String,
    },

    /// The Postgres DDL file cannot be written.
    #[error("failed to write geocoding DDL: {}", path.display())]
    WriteDdl {
        /// The `.sql` file.
        path: PathBuf,
        /// What the operating system said.
        #[source]
        source: std::io::Error,
    },

    /// The Wikimedia importance file cannot be opened.
    #[error("failed to open {}", path.display())]
    OpenImportance {
        /// The file.
        path: PathBuf,
        /// What the operating system said.
        #[source]
        source: std::io::Error,
    },

    /// The Wikimedia importance file cannot be read.
    #[error("failed to read {}", path.display())]
    ReadImportance {
        /// The file.
        path: PathBuf,
        /// What the reader said.
        #[source]
        source: std::io::Error,
    },
}

/// Result of the geocoding build.
pub type Result<T, E = SearchError> = std::result::Result<T, E>;