Skip to main content

modde_core/
error.rs

1use std::borrow::Cow;
2use std::path::PathBuf;
3
4use smallvec::SmallVec;
5
6use crate::resolver::GameId;
7
8#[derive(Debug, thiserror::Error)]
9pub enum CoreError {
10    #[error("IO error: {0}")]
11    Io(#[from] std::io::Error),
12
13    #[error("JSON deserialization error: {0}")]
14    Json(#[from] serde_json::Error),
15
16    #[error("TOML serialization error: {0}")]
17    TomlSer(#[from] toml::ser::Error),
18
19    #[error("TOML deserialization error: {0}")]
20    TomlDe(#[from] toml::de::Error),
21
22    #[error("database error: {0}")]
23    Database(#[from] rusqlite::Error),
24
25    #[error("invalid Nexus id: {0}")]
26    NexusId(#[from] crate::nexus_id::NexusIdError),
27
28    #[error("hash mismatch for {path}: expected {expected}, got {actual}")]
29    HashMismatch {
30        path: PathBuf,
31        expected: String,
32        actual: String,
33    },
34
35    #[error("dependency cycle detected involving mod {0}")]
36    DependencyCycle(String),
37
38    #[error("conflict: file '{path}' provided by multiple mods: {mods:?}")]
39    FileConflict {
40        path: String,
41        mods: Box<SmallVec<[String; 4]>>,
42    },
43
44    #[error("profile '{0}' not found")]
45    ProfileNotFound(String),
46
47    #[error("profile '{0}' already exists")]
48    ProfileAlreadyExists(String),
49
50    #[error(
51        "ambiguous profile name '{name}': found in games {games:?}. Use --game to disambiguate."
52    )]
53    AmbiguousProfile {
54        name: String,
55        games: SmallVec<[GameId; 4]>,
56    },
57
58    #[error("mod '{mod_id}' not found in profile '{profile}'. Available: {candidates:?}")]
59    ModNotFound {
60        profile: String,
61        mod_id: String,
62        candidates: SmallVec<[String; 5]>,
63    },
64
65    #[error("game '{0}' not detected")]
66    GameNotDetected(String),
67
68    #[error("save '{path}' is already assigned to profile '{profile}'")]
69    SaveAlreadyAssigned { path: String, profile: String },
70
71    #[error("no active profile for game '{0}'")]
72    NoActiveProfile(String),
73
74    #[error("not in experiment mode for game '{0}'")]
75    NotInExperiment(String),
76
77    #[error("save vault error: {0}")]
78    SaveVaultError(String),
79
80    #[error("game '{game_id}' has {save_count} existing saves that need adoption")]
81    SaveAdoptionRequired { game_id: GameId, save_count: usize },
82
83    #[error("unsupported filesystem operation: {0}")]
84    UnsupportedFs(Cow<'static, str>),
85
86    #[error("validation error: {0}")]
87    Validation(Cow<'static, str>),
88
89    #[error("{0}")]
90    Other(Cow<'static, str>),
91}
92
93pub type Result<T> = std::result::Result<T, CoreError>;