Skip to main content

systemprompt_cloud/error/
messages.rs

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