Cotton code
63 lines · 2.1 KB · RustRaw
//! Every way the store refuses.//!//! The named migration error (`Migration`) plus the two//! shapes the driver and the codecs need. The MESSAGES matter: the Mac's//! window and the phone's boot screen render them, and the conformance//! harness compares the reason strings a rejection carries — so the wording//! is fixed, never reinvented.use std::fmt;/// The result every fallible call in this crate returns.pub type Result<T> = std::result::Result<T, StoreError>;#[derive(Debug, thiserror::Error)]pub enum StoreError {    /// SQLite said no.    #[error("sqlite: {0}")]    Sqlite(#[from] rusqlite::Error),    /// An open that failed one of its assertions — `PRAGMA foreign_keys` off,    /// FTS5 missing, a second identity in a file that already has one. The    /// file is untouched.    #[error("{0}")]    Refused(String),    /// A value could not be encoded into (or decoded out of) its column's    /// codec. Carries the TypeScript `TypeError` message verbatim.    #[error("{0}")]    Encode(String),    /// One migration step failed, and the file is exactly as it was before it:    /// the step ran inside a transaction that has already been rolled back.    #[error(        "cotton-store: migration {version} failed (file {from} → {to}); it ran in a transaction \         and has been rolled back, so the file is unchanged at version {from} and running the \         migration again is safe: {source}"    )]    Migration {        version: u32,        from: u32,        to: u32,        source: Box<StoreError>,    },}impl From<cotton_rules::fingerprint::EncodeError> for StoreError {    fn from(error: cotton_rules::fingerprint::EncodeError) -> Self {        StoreError::Encode(error.0)    }}impl StoreError {    /// A `TypeError`-shaped refusal from a codec.    pub fn encode(message: impl fmt::Display) -> Self {        StoreError::Encode(message.to_string())    }    /// An open (or a seed) that failed its assertions.    pub fn refused(message: impl fmt::Display) -> Self {        StoreError::Refused(message.to_string())    }}