Skip to main content

braze_sync/
error.rs

1//! Top-level error type for braze-sync.
2//!
3//! Library code returns `Result<T, Error>` defined here. The CLI layer
4//! wraps this with `anyhow` and maps variants to the frozen exit codes.
5
6use std::path::PathBuf;
7use thiserror::Error;
8
9pub type Result<T> = std::result::Result<T, Error>;
10
11#[derive(Error, Debug)]
12pub enum Error {
13    #[error("Braze API error: {0}")]
14    Api(#[from] crate::braze::error::BrazeApiError),
15
16    #[error("Configuration error: {0}")]
17    Config(String),
18
19    #[error("Missing environment variable: {0}")]
20    MissingEnv(String),
21
22    #[error("I/O error: {0}")]
23    Io(#[from] std::io::Error),
24
25    #[error("YAML parse error in {path}: {source}")]
26    YamlParse {
27        path: PathBuf,
28        #[source]
29        source: serde_norway::Error,
30    },
31
32    #[error("CSV parse error in {path}: {source}")]
33    CsvParse {
34        path: PathBuf,
35        #[source]
36        source: csv::Error,
37    },
38
39    #[error("Invalid file format in {path}: {message}")]
40    InvalidFormat { path: PathBuf, message: String },
41
42    #[error("Drift detected in {count} resource(s)")]
43    DriftDetected { count: usize },
44
45    #[error("Destructive change blocked: pass --allow-destructive to proceed")]
46    DestructiveBlocked,
47
48    #[error("Plan drift: saved plan does not match the freshly-computed plan")]
49    PlanDrift,
50
51    #[error("Rate limit exhausted after {retries} retries")]
52    RateLimitExhausted { retries: u32 },
53}