Skip to main content

kimberlite_migration/
error.rs

1//! Error types for migration system.
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Migration system errors.
7#[derive(Error, Debug)]
8pub enum Error {
9    /// IO error.
10    #[error("IO error: {0}")]
11    Io(#[from] std::io::Error),
12
13    /// Migration file parse error.
14    #[error("Failed to parse migration file {path}: {reason}")]
15    ParseError { path: PathBuf, reason: String },
16
17    /// Migration file not found.
18    #[error("Migration file not found: {0}")]
19    NotFound(PathBuf),
20
21    /// Invalid migration sequence.
22    #[error("Invalid migration sequence: expected {expected}, found {found}")]
23    InvalidSequence { expected: u32, found: u32 },
24
25    /// Checksum mismatch (tampering detected).
26    #[error("Checksum mismatch for migration {id}: expected {expected}, found {actual}")]
27    ChecksumMismatch {
28        id: u32,
29        expected: String,
30        actual: String,
31    },
32
33    /// Migration already applied.
34    #[error("Migration {0} has already been applied")]
35    AlreadyApplied(u32),
36
37    /// Invalid migration name.
38    #[error("Invalid migration name: {0}")]
39    InvalidName(String),
40
41    /// Lock file error.
42    #[error("Lock file error: {0}")]
43    LockFile(String),
44
45    /// TOML deserialization error.
46    #[error("TOML error: {0}")]
47    Toml(#[from] toml::de::Error),
48
49    /// TOML serialization error.
50    #[error("TOML serialization error: {0}")]
51    TomlSer(#[from] toml::ser::Error),
52}
53
54/// Result type for migration operations.
55pub type Result<T> = std::result::Result<T, Error>;