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::SessionStoreCorrupted { .. } => "CLI session store is stale or corrupt",
29 Self::OAuthFlow { .. } => "OAuth login flow failed",
30 Self::Deploy { .. } => "Cloud deploy failed",
31 Self::Dockerfile { .. } => "Dockerfile validation failed",
32 Self::Docker { .. } => "Docker command failed",
33 Self::Unauthorized => "Cloud API rejected this token",
34 Self::HttpStatus { .. } => "Cloud API returned a non-success status",
35 Self::Other { .. } => "Cloud operation failed",
36 }
37 }
38
39 pub const fn recovery_hint(&self) -> &'static str {
40 match self {
41 Self::NotAuthenticated | Self::TokenExpired | Self::Unauthorized => {
42 "Run 'systemprompt cloud login' to authenticate"
43 },
44 Self::JwtDecode | Self::CredentialsCorrupted { .. } => {
45 "Run 'systemprompt cloud login' to re-authenticate"
46 },
47 Self::TenantsNotSynced
48 | Self::TenantsStoreCorrupted { .. }
49 | Self::TenantsStoreInvalid { .. } => "Run 'systemprompt cloud login' to sync tenants",
50 Self::ApiError { .. } | Self::HttpStatus { .. } | Self::ApiValidationFailed { .. } => {
51 "Check the error message and try again"
52 },
53 Self::Network(_) => "Check your internet connection and try again",
54 Self::Io(_) => "Check file permissions and disk space",
55 Self::Json(_) => "Inspect the JSON file referenced in the error message",
56 Self::InvalidCredentials { .. } | Self::CredentialsFileNotFound { .. } => {
57 "Run 'systemprompt cloud login' to refresh credentials"
58 },
59 Self::CredentialsNotInitialized | Self::CredentialsAlreadyInitialized => {
60 "Restart the process to re-run the bootstrap sequence"
61 },
62 Self::SessionVersionMismatch { .. } => "Delete the session file and re-authenticate",
63 Self::SessionStoreCorrupted { .. } => {
64 "Run 'systemprompt admin session switch <profile>' to reset the session store"
65 },
66 Self::OAuthFlow { .. } => "Re-run the OAuth login flow",
67 Self::Dockerfile { .. } => {
68 "Regenerate the Dockerfile with 'systemprompt cloud profile create'"
69 },
70 Self::Docker { .. } => "Check that Docker is installed and running",
71 Self::Deploy { .. } | Self::Other { .. } => "Inspect the error message and try again",
72 }
73 }
74
75 pub const fn requires_login(&self) -> bool {
76 matches!(
77 self,
78 Self::NotAuthenticated
79 | Self::TokenExpired
80 | Self::CredentialsCorrupted { .. }
81 | Self::Unauthorized
82 )
83 }
84}