systemprompt_cloud/error/
mod.rs1use thiserror::Error;
16
17mod messages;
18
19pub type CloudResult<T> = Result<T, CloudError>;
20
21#[derive(Debug, Error)]
22#[non_exhaustive]
23pub enum CloudError {
24 #[error("Authentication required.\n\nRun: systemprompt cloud auth login")]
25 NotAuthenticated,
26
27 #[error("Token expired.\n\nRun: systemprompt cloud auth login")]
28 TokenExpired,
29
30 #[error("JWT decode error")]
31 JwtDecode,
32
33 #[error("Credentials file corrupted.\n\nRun: systemprompt cloud auth login")]
34 CredentialsCorrupted {
35 #[source]
36 source: serde_json::Error,
37 },
38
39 #[error("Tenants not synced.\n\nRun: systemprompt cloud auth login")]
40 TenantsNotSynced,
41
42 #[error("Tenants store corrupted.\n\nRun: systemprompt cloud auth login")]
43 TenantsStoreCorrupted {
44 #[source]
45 source: serde_json::Error,
46 },
47
48 #[error("Tenants store invalid: {message}")]
49 TenantsStoreInvalid { message: String },
50
51 #[error("API error: {message}")]
52 ApiError { message: String },
53
54 #[error(transparent)]
55 Network(#[from] reqwest::Error),
56
57 #[error(transparent)]
58 Io(#[from] std::io::Error),
59
60 #[error(transparent)]
61 Json(#[from] serde_json::Error),
62
63 #[error("Cloud API validation failed: {message}")]
64 ApiValidationFailed { message: String },
65
66 #[error("Cloud credentials file invalid: {message}")]
67 InvalidCredentials { message: String },
68
69 #[error("Cloud credentials file not found: {path}")]
70 CredentialsFileNotFound { path: String },
71
72 #[error("Credentials not initialized")]
73 CredentialsNotInitialized,
74
75 #[error("Credentials already initialized")]
76 CredentialsAlreadyInitialized,
77
78 #[error(
79 "Session file version mismatch: expected {min}-{max}, got {actual}. Delete {path} and \
80 retry."
81 )]
82 SessionVersionMismatch {
83 min: u32,
84 max: u32,
85 actual: u32,
86 path: String,
87 },
88
89 #[error(
90 "Session store at {path} is stale or corrupt and cannot be parsed.\n\nRun: systemprompt \
91 admin session switch <profile> to reset it"
92 )]
93 SessionStoreCorrupted {
94 path: String,
95 #[source]
96 source: serde_json::Error,
97 },
98
99 #[error("OAuth flow failed: {message}")]
100 OAuthFlow { message: String },
101
102 #[error("{message}")]
103 Deploy {
104 message: String,
105 #[source]
106 source: Option<DeploySource>,
107 },
108
109 #[error("{message}")]
110 Dockerfile { message: String },
111
112 #[error("{message}")]
113 Docker {
114 message: String,
115 #[source]
116 source: Option<std::io::Error>,
117 },
118
119 #[error("Authentication failed. Please run 'systemprompt cloud auth login' again.")]
120 Unauthorized,
121
122 #[error("Request failed with status {status}: {body}")]
123 HttpStatus { status: u16, body: String },
124
125 #[error("{message}")]
126 Other { message: String },
127}
128
129impl CloudError {
130 pub fn other(message: impl Into<String>) -> Self {
131 Self::Other {
132 message: message.into(),
133 }
134 }
135
136 pub fn deploy(message: impl Into<String>) -> Self {
137 Self::Deploy {
138 message: message.into(),
139 source: None,
140 }
141 }
142
143 pub fn deploy_with(message: impl Into<String>, source: impl Into<DeploySource>) -> Self {
144 Self::Deploy {
145 message: message.into(),
146 source: Some(source.into()),
147 }
148 }
149
150 pub fn dockerfile(message: impl Into<String>) -> Self {
151 Self::Dockerfile {
152 message: message.into(),
153 }
154 }
155
156 pub fn docker(message: impl Into<String>) -> Self {
157 Self::Docker {
158 message: message.into(),
159 source: None,
160 }
161 }
162
163 pub fn docker_with(message: impl Into<String>, source: std::io::Error) -> Self {
164 Self::Docker {
165 message: message.into(),
166 source: Some(source),
167 }
168 }
169
170 pub const fn is_missing_credentials_file(&self) -> bool {
171 matches!(self, Self::CredentialsFileNotFound { .. })
172 }
173
174 pub const fn is_local_mode_recoverable(&self) -> bool {
175 matches!(
176 self,
177 Self::CredentialsFileNotFound { .. }
178 | Self::TokenExpired
179 | Self::ApiValidationFailed { .. }
180 )
181 }
182}
183
184#[derive(Debug, thiserror::Error)]
186pub enum DeploySource {
187 #[error(transparent)]
188 Io(#[from] std::io::Error),
189 #[error(transparent)]
190 Json(#[from] serde_json::Error),
191}