geolith-tiles-builder 0.4.2

Builds tiles from OpenStreetMap and Overture Maps: protomaps-schema vector PMTiles, Terrain-RGB, raster archives and 3D Tiles from Gaussian splats
Documentation
//! The error of the sort runs.

use std::path::PathBuf;

use crate::sort::block::BlockError;

/// Why a sort run cannot be written or read.
///
/// A run that is cut, damaged or written by another version never yields a
/// wrong entry: the reader stops with one of these.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SortRunError {
    /// A file operation on a run failed.
    #[error("{op} {}", path.display())]
    Io {
        /// What was being done: `create`, `write`, `read`, `open`, `remove`.
        op: &'static str,
        /// The run file.
        path: PathBuf,
        /// What the operating system said.
        #[source]
        source: std::io::Error,
    },

    /// The file does not start like a sort run. Runs of an older version of
    /// geolith have another layout: delete the folder and run phase 1 again.
    #[error(
        "{} is not a sort run of this version; delete the sort folder and build again",
        path.display()
    )]
    NotARun {
        /// The file.
        path: PathBuf,
    },

    /// The run was written with a layout this version does not know.
    #[error("{} has run layout {found}; this version reads layout {expected}", path.display())]
    UnsupportedLayout {
        /// The file.
        path: PathBuf,
        /// The layout number in the file.
        found: u8,
        /// The layout number this version reads.
        expected: u8,
    },

    /// The file ends before the end marker: the write was cut, for example
    /// by a full disk or a crash.
    #[error("{} is cut: it ends at byte {at} without an end marker", path.display())]
    Truncated {
        /// The file.
        path: PathBuf,
        /// Where the file ended.
        at: u64,
    },

    /// A block does not match its checksum: the disk or a copy damaged it.
    #[error("{} is damaged: block {block} (at byte {at}) fails its checksum", path.display())]
    BadChecksum {
        /// The file.
        path: PathBuf,
        /// The block number, from 0.
        block: u64,
        /// Where the block starts.
        at: u64,
    },

    /// A block passes its checksum but does not decode, or an entry cannot
    /// be encoded.
    #[error("{} has a bad block {block}: {source}", path.display())]
    BadBlock {
        /// The file.
        path: PathBuf,
        /// The block number, from 0.
        block: u64,
        /// What is wrong with the block.
        #[source]
        source: BlockError,
    },

    /// A block header or the end marker states a size that cannot be true.
    #[error("{} has a bad header at byte {at}: {what}", path.display())]
    BadHeader {
        /// The file.
        path: PathBuf,
        /// Where the header starts.
        at: u64,
        /// What is wrong.
        what: &'static str,
    },

    /// The end marker counts other blocks or entries than the file holds.
    #[error(
        "{} ends with {found} entries but its end marker says {expected}",
        path.display()
    )]
    CountMismatch {
        /// The file.
        path: PathBuf,
        /// The entries the end marker says.
        expected: u64,
        /// The entries the reader found.
        found: u64,
    },

    /// Bytes follow the end marker.
    #[error("{} has bytes after its end marker", path.display())]
    TrailingBytes {
        /// The file.
        path: PathBuf,
    },
}