Skip to main content

busbar_sf_tooling/
error.rs

1//! Error types for sf-tooling.
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, thiserror::Error)]
6#[error("{kind}")]
7pub struct Error {
8    pub kind: ErrorKind,
9    #[source]
10    pub source: Option<Box<dyn std::error::Error + Send + Sync>>,
11}
12
13impl Error {
14    pub fn new(kind: ErrorKind) -> Self {
15        Self { kind, source: None }
16    }
17}
18
19#[derive(Debug, thiserror::Error)]
20pub enum ErrorKind {
21    #[error("Client error: {0}")]
22    Client(String),
23
24    #[error("Salesforce error: {error_code} - {message}")]
25    Salesforce { error_code: String, message: String },
26
27    #[error("Apex compilation error: {0}")]
28    ApexCompilation(String),
29
30    #[error("Apex execution error: {0}")]
31    ApexExecution(String),
32
33    #[error("{0}")]
34    Other(String),
35}
36
37impl From<busbar_sf_client::Error> for Error {
38    fn from(err: busbar_sf_client::Error) -> Self {
39        Error {
40            kind: ErrorKind::Client(err.to_string()),
41            source: Some(Box::new(err)),
42        }
43    }
44}