//! Errors for the blob store.

use crate::store::BlobId;

/// Errors surfaced by `BlobStore`.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// Underlying filesystem IO failure.
    #[error("filesystem io: {0}")]
    Io(#[from] std::io::Error),
    /// The requested blob does not exist in the store.
    #[error("blob not found: {0:?}")]
    NotFound(BlobId),
    /// The bytes on disk did not hash to the requested id (storage corruption).
    #[error("corrupt blob: expected {expected:?} got {actual:?}")]
    Corrupt {
        /// Hash the caller asked for.
        expected: BlobId,
        /// Hash actually computed from the on-disk bytes.
        actual: BlobId,
    },
    /// Atomic persistence (tmpfile rename) failed.
    #[error("persist: {0}")]
    Persist(String),
}

/// Convenience alias.
pub type Result<T> = std::result::Result<T, Error>;
