Skip to main content

datasynth_core/country/
error.rs

1//! Error types for country pack loading and validation.
2
3use thiserror::Error;
4
5/// Errors that can occur when working with country packs.
6#[derive(Error, Debug)]
7pub enum CountryPackError {
8    /// Invalid or unrecognized country code.
9    #[error("Invalid country code: {0}")]
10    InvalidCountryCode(String),
11
12    /// Failed to parse a country pack JSON file.
13    #[error("Failed to parse country pack: {0}")]
14    ParseError(String),
15
16    /// Error during deep-merge of pack overrides.
17    #[error("Merge error: {0}")]
18    MergeError(String),
19
20    /// Error accessing external pack directory.
21    #[error("Directory error: {0}")]
22    DirectoryError(String),
23
24    /// Schema version mismatch between packs.
25    #[error("Schema version mismatch: expected {expected}, found {found}")]
26    SchemaVersionMismatch { expected: String, found: String },
27}
28
29impl CountryPackError {
30    pub fn parse(msg: impl Into<String>) -> Self {
31        Self::ParseError(msg.into())
32    }
33
34    pub fn merge(msg: impl Into<String>) -> Self {
35        Self::MergeError(msg.into())
36    }
37
38    pub fn directory(msg: impl Into<String>) -> Self {
39        Self::DirectoryError(msg.into())
40    }
41}