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
45impl SyncError {
46    pub const fn is_retryable(&self) -> bool {
47        matches!(self, Self::Http(_))
48            || matches!(
49                self,
50                Self::ApiError { status, .. }
51                    if *status == 502 || *status == 503 || *status == 504 || *status == 429
52            )
53    }
54}
55
56pub type SyncResult<T> = Result<T, SyncError>;