Skip to main content

systemprompt_sync/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum SyncError {
5    #[error("API error {status}: {message}")]
6    ApiError { status: u16, message: String },
7
8    #[error("Unauthorized - run 'systemprompt cloud login'")]
9    Unauthorized,
10
11    #[error("Tenant has no associated app")]
12    TenantNoApp,
13
14    #[error("Must run from project root (with infrastructure/ directory)")]
15    NotProjectRoot,
16
17    #[error("Command failed: {command}")]
18    CommandFailed { command: String },
19
20    #[error("Docker login failed")]
21    DockerLoginFailed,
22
23    #[error("Git SHA unavailable")]
24    GitShaUnavailable,
25
26    #[error("Missing configuration: {0}")]
27    MissingConfig(String),
28
29    #[error("IO error: {0}")]
30    Io(#[from] std::io::Error),
31
32    #[error("HTTP error: {0}")]
33    Http(#[from] reqwest::Error),
34
35    #[error("JSON error: {0}")]
36    Json(#[from] serde_json::Error),
37
38    #[error("Database error: {0}")]
39    Database(#[from] sqlx::Error),
40
41    #[error("Path error: {0}")]
42    StripPrefix(#[from] std::path::StripPrefixError),
43
44    #[error("Zip error: {0}")]
45    Zip(#[from] zip::result::ZipError),
46}
47
48impl SyncError {
49    pub const fn is_retryable(&self) -> bool {
50        matches!(self, Self::Http(_))
51            || matches!(
52                self,
53                Self::ApiError { status, .. }
54                    if *status == 502 || *status == 503 || *status == 504 || *status == 429
55            )
56    }
57}
58
59pub type SyncResult<T> = Result<T, SyncError>;