systemprompt_cloud/error/
messages.rs1use 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::TenantNotConfigured => "No project linked to this environment",
11 Self::AppNotConfigured => "No deployment target configured",
12 Self::ProfileRequired { .. } => "Profile configuration required",
13 Self::MissingProfileField { .. } => "Missing required profile field",
14 Self::JwtDecode => "Failed to decode authentication token",
15 Self::CredentialsCorrupted { .. } => "Credentials file is corrupted",
16 Self::TenantsNotSynced => "Tenants not synced locally",
17 Self::TenantsStoreCorrupted { .. } => "Tenants store is corrupted",
18 Self::TenantsStoreInvalid { .. } => "Tenants store is invalid",
19 Self::TenantNotFound { .. } => "Tenant not found",
20 Self::ApiError { .. } => "API request failed",
21 Self::Network(_) => "Network error communicating with cloud",
22 Self::Io(_) => "File system error",
23 Self::Json(_) => "JSON parse error",
24 Self::ApiValidationFailed { .. } => "Cloud API rejected credentials",
25 Self::InvalidCredentials { .. } => "Stored credentials are invalid",
26 Self::CredentialsFileNotFound { .. } => "Credentials file is missing",
27 Self::CredentialsNotInitialized => "Credentials bootstrap not initialised",
28 Self::CredentialsAlreadyInitialized => "Credentials bootstrap already initialised",
29 Self::SessionVersionMismatch { .. } => "CLI session file is out of date",
30 Self::OAuthFlow { .. } => "OAuth login flow failed",
31 Self::CheckoutFlow { .. } => "Cloud checkout flow failed",
32 Self::SseStream { .. } => "Cloud SSE stream failed",
33 Self::ProvisioningFailed { .. } => "Tenant provisioning failed",
34 Self::Unauthorized => "Cloud API rejected this token",
35 Self::HttpStatus { .. } => "Cloud API returned a non-success status",
36 Self::Other { .. } => "Cloud operation failed",
37 }
38 }
39
40 pub const fn recovery_hint(&self) -> &'static str {
41 match self {
42 Self::NotAuthenticated | Self::TokenExpired | Self::Unauthorized => {
43 "Run 'systemprompt cloud login' to authenticate"
44 },
45 Self::TenantNotConfigured | Self::AppNotConfigured => {
46 "Run 'systemprompt cloud setup' to configure your project"
47 },
48 Self::ProfileRequired { .. } => {
49 "Set SYSTEMPROMPT_PROFILE or run 'systemprompt cloud config'"
50 },
51 Self::MissingProfileField { .. } => "Add the missing field to your profile YAML",
52 Self::JwtDecode | Self::CredentialsCorrupted { .. } => {
53 "Run 'systemprompt cloud login' to re-authenticate"
54 },
55 Self::TenantsNotSynced
56 | Self::TenantsStoreCorrupted { .. }
57 | Self::TenantsStoreInvalid { .. } => "Run 'systemprompt cloud login' to sync tenants",
58 Self::TenantNotFound { .. } => {
59 "Run 'systemprompt cloud config' to select a valid tenant"
60 },
61 Self::ApiError { .. } | Self::HttpStatus { .. } | Self::ApiValidationFailed { .. } => {
62 "Check the error message and try again"
63 },
64 Self::Network(_) => "Check your internet connection and try again",
65 Self::Io(_) => "Check file permissions and disk space",
66 Self::Json(_) => "Inspect the JSON file referenced in the error message",
67 Self::InvalidCredentials { .. } | Self::CredentialsFileNotFound { .. } => {
68 "Run 'systemprompt cloud login' to refresh credentials"
69 },
70 Self::CredentialsNotInitialized | Self::CredentialsAlreadyInitialized => {
71 "Restart the process to re-run the bootstrap sequence"
72 },
73 Self::SessionVersionMismatch { .. } => "Delete the session file and re-authenticate",
74 Self::OAuthFlow { .. } => "Re-run the OAuth login flow",
75 Self::CheckoutFlow { .. } => "Re-run the checkout flow",
76 Self::SseStream { .. } => "Retry the operation; the server falls back to polling",
77 Self::ProvisioningFailed { .. } => "Inspect 'systemprompt cloud status' for details",
78 Self::Other { .. } => "Inspect the error message and try again",
79 }
80 }
81
82 pub const fn requires_login(&self) -> bool {
83 matches!(
84 self,
85 Self::NotAuthenticated
86 | Self::TokenExpired
87 | Self::CredentialsCorrupted { .. }
88 | Self::Unauthorized
89 )
90 }
91
92 pub const fn requires_setup(&self) -> bool {
93 matches!(self, Self::TenantNotConfigured | Self::AppNotConfigured)
94 }
95}