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//! from IMPLEMENTATION.md ยง7.1.
6
7use std::path::PathBuf;
8use thiserror::Error;
9
10pub type Result<T> = std::result::Result<T, Error>;
11
12#[derive(Error, Debug)]
13pub enum Error {
14    #[error("Braze API error: {0}")]
15    Api(#[from] crate::braze::error::BrazeApiError),
16
17    #[error("Configuration error: {0}")]
18    Config(String),
19
20    #[error("Missing environment variable: {0}")]
21    MissingEnv(String),
22
23    #[error("I/O error: {0}")]
24    Io(#[from] std::io::Error),
25
26    #[error("YAML parse error in {path}: {source}")]
27    YamlParse {
28        path: PathBuf,
29        #[source]
30        source: serde_norway::Error,
31    },
32
33    #[error("CSV parse error in {path}: {source}")]
34    CsvParse {
35        path: PathBuf,
36        #[source]
37        source: csv::Error,
38    },
39
40    #[error("Invalid file format in {path}: {message}")]
41    InvalidFormat { path: PathBuf, message: String },
42
43    #[error("Drift detected in {count} resource(s)")]
44    DriftDetected { count: usize },
45
46    #[error("Destructive change blocked: pass --allow-destructive to proceed")]
47    DestructiveBlocked,
48
49    #[error("Plan drift: saved plan does not match the freshly-computed plan")]
50    PlanDrift,
51
52    #[error("Rate limit exhausted after {retries} retries")]
53    RateLimitExhausted { retries: u32 },
54}