Skip to main content

ankit_builder/
error.rs

1//! Error types for ankit-builder.
2
3use thiserror::Error;
4
5/// Result type for ankit-builder operations.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors that can occur during deck building.
9#[derive(Debug, Error)]
10pub enum Error {
11    /// TOML parsing error.
12    #[error("TOML parse error: {0}")]
13    TomlParse(#[from] toml::de::Error),
14
15    /// TOML serialization error.
16    #[error("TOML serialize error: {0}")]
17    TomlSerialize(String),
18
19    /// IO error.
20    #[error("IO error: {0}")]
21    Io(#[from] std::io::Error),
22
23    /// Model not found in deck definition.
24    #[error("model not found: {0}")]
25    ModelNotFound(String),
26
27    /// Deck not found in deck definition.
28    #[error("deck not found: {0}")]
29    DeckNotFound(String),
30
31    /// Field not found in model.
32    #[error("field '{field}' not found in model '{model}'")]
33    FieldNotFound {
34        /// Model name.
35        model: String,
36        /// Field name.
37        field: String,
38    },
39
40    /// Missing required field.
41    #[error("missing required field '{field}' in model '{model}'")]
42    MissingRequiredField {
43        /// Model name.
44        model: String,
45        /// Field name.
46        field: String,
47    },
48
49    /// Media file not found.
50    #[error("media file not found: {0}")]
51    MediaNotFound(String),
52
53    /// Invalid deck definition.
54    #[error("invalid deck definition: {0}")]
55    InvalidDefinition(String),
56
57    /// SQLite error (apkg feature).
58    #[cfg(feature = "apkg")]
59    #[error("SQLite error: {0}")]
60    Sqlite(#[from] rusqlite::Error),
61
62    /// ZIP error (apkg feature).
63    #[cfg(feature = "apkg")]
64    #[error("ZIP error: {0}")]
65    Zip(#[from] zip::result::ZipError),
66
67    /// AnkiConnect error (connect feature).
68    #[cfg(feature = "connect")]
69    #[error("AnkiConnect error: {0}")]
70    AnkiConnect(#[from] ankit::Error),
71
72    /// Sync conflict error (connect feature).
73    #[cfg(feature = "connect")]
74    #[error("sync conflict: {0}")]
75    SyncConflict(String),
76}