systemprompt_cloud/error/
messages.rs1use super::CloudError;
7
8impl CloudError {
9 pub const fn user_message(&self) -> &'static str {
10 match self {
11 Self::NotAuthenticated => "Not logged in to systemprompt.io Cloud",
12 Self::TokenExpired => "Your session has expired",
13 Self::JwtDecode => "Failed to decode authentication token",
14 Self::CredentialsCorrupted { .. } => "Credentials file is corrupted",
15 Self::TenantsNotSynced => "Tenants not synced locally",
16 Self::TenantsStoreCorrupted { .. } => "Tenants store is corrupted",
17 Self::TenantsStoreInvalid { .. } => "Tenants store is invalid",
18 Self::ApiError { .. } => "API request failed",
19 Self::Network(_) => "Network error communicating with cloud",
20 Self::Io(_) => "File system error",
21 Self::Json(_) => "JSON parse error",
22 Self::ApiValidationFailed { .. } => "Cloud API rejected credentials",
23 Self::InvalidCredentials { .. } => "Stored credentials are invalid",
24 Self::CredentialsFileNotFound { .. } => "Credentials file is missing",
25 Self::CredentialsNotInitialized => "Credentials bootstrap not initialised",
26 Self::CredentialsAlreadyInitialized => "Credentials bootstrap already initialised",
27 Self::SessionVersionMismatch { .. } => "CLI session file is out of date",
28 Self::OAuthFlow { .. } => "OAuth login flow failed",
29 Self::CheckoutFlow { .. } => "Cloud checkout flow failed",
30 Self::SseStream { .. } => "Cloud SSE stream failed",
31 Self::ProvisioningFailed { .. } => "Tenant provisioning failed",
32 Self::Deploy { .. } => "Cloud deploy failed",
33 Self::Dockerfile { .. } => "Dockerfile validation failed",
34 Self::Docker { .. } => "Docker command failed",
35 Self::Unauthorized => "Cloud API rejected this token",
36 Self::HttpStatus { .. } => "Cloud API returned a non-success status",
37 Self::Other { .. } => "Cloud operation failed",
38 }
39 }
40
41 pub const fn recovery_hint(&self) -> &'static str {
42 match self {
43 Self::NotAuthenticated | Self::TokenExpired | Self::Unauthorized => {
44 "Run 'systemprompt cloud login' to authenticate"
45 },
46 Self::JwtDecode | Self::CredentialsCorrupted { .. } => {
47 "Run 'systemprompt cloud login' to re-authenticate"
48 },
49 Self::TenantsNotSynced
50 | Self::TenantsStoreCorrupted { .. }
51 | Self::TenantsStoreInvalid { .. } => "Run 'systemprompt cloud login' to sync tenants",
52 Self::ApiError { .. } | Self::HttpStatus { .. } | Self::ApiValidationFailed { .. } => {
53 "Check the error message and try again"
54 },
55 Self::Network(_) => "Check your internet connection and try again",
56 Self::Io(_) => "Check file permissions and disk space",
57 Self::Json(_) => "Inspect the JSON file referenced in the error message",
58 Self::InvalidCredentials { .. } | Self::CredentialsFileNotFound { .. } => {
59 "Run 'systemprompt cloud login' to refresh credentials"
60 },
61 Self::CredentialsNotInitialized | Self::CredentialsAlreadyInitialized => {
62 "Restart the process to re-run the bootstrap sequence"
63 },
64 Self::SessionVersionMismatch { .. } => "Delete the session file and re-authenticate",
65 Self::OAuthFlow { .. } => "Re-run the OAuth login flow",
66 Self::CheckoutFlow { .. } => "Re-run the checkout flow",
67 Self::SseStream { .. } => "Retry the operation; the server falls back to polling",
68 Self::ProvisioningFailed { .. } => "Inspect 'systemprompt cloud status' for details",
69 Self::Dockerfile { .. } => {
70 "Regenerate the Dockerfile with 'systemprompt cloud profile create'"
71 },
72 Self::Docker { .. } => "Check that Docker is installed and running",
73 Self::Deploy { .. } | Self::Other { .. } => "Inspect the error message and try again",
74 }
75 }
76
77 pub const fn requires_login(&self) -> bool {
78 matches!(
79 self,
80 Self::NotAuthenticated
81 | Self::TokenExpired
82 | Self::CredentialsCorrupted { .. }
83 | Self::Unauthorized
84 )
85 }
86}