Skip to main content

stackless_provider_sdk/
error.rs

1use stackless_core::fault::{ErrorContext, Fault, codes};
2
3use stackless_stripe_projects::ProjectsError;
4
5#[derive(Debug, thiserror::Error)]
6pub enum IntegrationError {
7    #[error("[{location}] is invalid: {detail}")]
8    ConfigInvalid { location: String, detail: String },
9
10    #[error("integration provider {provider:?} is not supported on host {host:?}")]
11    HostUnsupported { provider: String, host: String },
12
13    #[error("provisioning integration {integration:?} failed: {detail}")]
14    ProvisionFailed { integration: String, detail: String },
15
16    #[error(transparent)]
17    Stripe(#[from] ProjectsError),
18}
19
20impl Fault for IntegrationError {
21    fn code(&self) -> &'static str {
22        match self {
23            Self::ConfigInvalid { .. } => codes::INTEGRATION_CONFIG_INVALID,
24            Self::HostUnsupported { .. } => codes::INTEGRATION_HOST_UNSUPPORTED,
25            Self::ProvisionFailed { .. } => codes::STRIPE_PROJECTS_PROVISION_FAILED,
26            Self::Stripe(err) => err.code(),
27        }
28    }
29
30    fn remediation(&self) -> String {
31        match self {
32            Self::ConfigInvalid { location, .. } => {
33                format!("fix the [{location}] block in stackless.toml and re-run `check`")
34            }
35            Self::HostUnsupported { provider, host } => format!(
36                "remove or change integration {provider:?}, or re-run on a host that supports \
37                 it (not {host:?})"
38            ),
39            Self::ProvisionFailed { integration, .. } => format!(
40                "inspect Stripe Projects status for integration {integration:?} and re-run `up`"
41            ),
42            Self::Stripe(err) => err.remediation(),
43        }
44    }
45
46    fn context(&self) -> ErrorContext {
47        match self {
48            Self::Stripe(err) => err.context(),
49            _ => ErrorContext::default(),
50        }
51    }
52}