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::Deploy { .. } => "Cloud deploy failed",
35 Self::Dockerfile { .. } => "Dockerfile validation failed",
36 Self::Docker { .. } => "Docker command failed",
37 Self::Unauthorized => "Cloud API rejected this token",
38 Self::HttpStatus { .. } => "Cloud API returned a non-success status",
39 Self::Other { .. } => "Cloud operation failed",
40 }
41 }
42
43 pub const fn recovery_hint(&self) -> &'static str {
44 match self {
45 Self::NotAuthenticated | Self::TokenExpired | Self::Unauthorized => {
46 "Run 'systemprompt cloud login' to authenticate"
47 },
48 Self::TenantNotConfigured | Self::AppNotConfigured => {
49 "Run 'systemprompt cloud setup' to configure your project"
50 },
51 Self::ProfileRequired { .. } => {
52 "Set SYSTEMPROMPT_PROFILE or run 'systemprompt cloud config'"
53 },
54 Self::MissingProfileField { .. } => "Add the missing field to your profile YAML",
55 Self::JwtDecode | Self::CredentialsCorrupted { .. } => {
56 "Run 'systemprompt cloud login' to re-authenticate"
57 },
58 Self::TenantsNotSynced
59 | Self::TenantsStoreCorrupted { .. }
60 | Self::TenantsStoreInvalid { .. } => "Run 'systemprompt cloud login' to sync tenants",
61 Self::TenantNotFound { .. } => {
62 "Run 'systemprompt cloud config' to select a valid tenant"
63 },
64 Self::ApiError { .. } | Self::HttpStatus { .. } | Self::ApiValidationFailed { .. } => {
65 "Check the error message and try again"
66 },
67 Self::Network(_) => "Check your internet connection and try again",
68 Self::Io(_) => "Check file permissions and disk space",
69 Self::Json(_) => "Inspect the JSON file referenced in the error message",
70 Self::InvalidCredentials { .. } | Self::CredentialsFileNotFound { .. } => {
71 "Run 'systemprompt cloud login' to refresh credentials"
72 },
73 Self::CredentialsNotInitialized | Self::CredentialsAlreadyInitialized => {
74 "Restart the process to re-run the bootstrap sequence"
75 },
76 Self::SessionVersionMismatch { .. } => "Delete the session file and re-authenticate",
77 Self::OAuthFlow { .. } => "Re-run the OAuth login flow",
78 Self::CheckoutFlow { .. } => "Re-run the checkout flow",
79 Self::SseStream { .. } => "Retry the operation; the server falls back to polling",
80 Self::ProvisioningFailed { .. } => "Inspect 'systemprompt cloud status' for details",
81 Self::Dockerfile { .. } => {
82 "Regenerate the Dockerfile with 'systemprompt cloud profile create'"
83 },
84 Self::Docker { .. } => "Check that Docker is installed and running",
85 Self::Deploy { .. } | Self::Other { .. } => "Inspect the error message and try again",
86 }
87 }
88
89 pub const fn requires_login(&self) -> bool {
90 matches!(
91 self,
92 Self::NotAuthenticated
93 | Self::TokenExpired
94 | Self::CredentialsCorrupted { .. }
95 | Self::Unauthorized
96 )
97 }
98
99 pub const fn requires_setup(&self) -> bool {
100 matches!(self, Self::TenantNotConfigured | Self::AppNotConfigured)
101 }
102}