Skip to main content

systemprompt_cloud/error/
messages.rs

1//! User-facing message + recovery-hint helpers for [`super::CloudError`].
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use 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::TenantAlreadyExists { .. } => "Tenant already exists",
19            Self::TenantNotSelfManaged { .. } => "Tenant is managed by systemprompt.io",
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::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::ProviderNotDeployable { .. } => "This provider has no deploy pipeline",
36            Self::DeployNotConfigured { .. } => "Deploy target is not configured",
37            Self::GitOps { .. } => "GitOps update failed",
38            Self::ValuesFile { .. } => "Values file could not be updated",
39            Self::TenantUnready { .. } => "Tenant did not become ready",
40            Self::OperatorAuth { .. }
41            | Self::OperatorEndpoint { .. }
42            | Self::OperatorEmail { .. } => "Operator sign-in failed",
43            Self::OperatorNotAuthenticated => "Not signed in as an operator",
44        }
45    }
46
47    pub const fn recovery_hint(&self) -> &'static str {
48        match self {
49            Self::NotAuthenticated | Self::TokenExpired | Self::Unauthorized => {
50                "Run 'systemprompt cloud auth login' to authenticate"
51            },
52            Self::JwtDecode | Self::CredentialsCorrupted { .. } => {
53                "Run 'systemprompt cloud auth login' to re-authenticate"
54            },
55            Self::TenantsNotSynced
56            | Self::TenantsStoreCorrupted { .. }
57            | Self::TenantsStoreInvalid { .. } => {
58                "Run 'systemprompt cloud auth login' to sync tenants"
59            },
60            Self::TenantAlreadyExists { .. } => {
61                "Choose another id, or remove the existing record first"
62            },
63            Self::TenantNotSelfManaged { .. } => {
64                "Use 'systemprompt cloud tenant delete' for systemprompt.io tenants"
65            },
66            Self::ApiError { .. } | Self::HttpStatus { .. } | Self::ApiValidationFailed { .. } => {
67                "Check the error message and try again"
68            },
69            Self::Network(_) => "Check your internet connection and try again",
70            Self::Io(_) => "Check file permissions and disk space",
71            Self::Json(_) => "Inspect the JSON file referenced in the error message",
72            Self::InvalidCredentials { .. } | Self::CredentialsFileNotFound { .. } => {
73                "Run 'systemprompt cloud auth login' to refresh credentials"
74            },
75            Self::SessionVersionMismatch { .. } => "Delete the session file and re-authenticate",
76            Self::SessionStoreCorrupted { .. } => {
77                "Run 'systemprompt admin session switch <profile>' to reset the session store"
78            },
79            Self::OAuthFlow { .. } => "Re-run the OAuth login flow",
80            Self::Dockerfile { .. } => {
81                "Regenerate the Dockerfile with 'systemprompt cloud profile create'"
82            },
83            Self::Docker { .. } => "Check that Docker is installed and running",
84            Self::Deploy { .. } => "Inspect the error message and try again",
85            Self::ProviderNotDeployable { .. } => {
86                "Run the tenant locally with 'systemprompt infra services start'"
87            },
88            Self::DeployNotConfigured { .. } => {
89                "Add cloud.deploy (registry, repository, gitops) to the profile"
90            },
91            Self::GitOps { .. } | Self::ValuesFile { .. } => {
92                "Check the ops repository working copy and cloud.deploy.gitops settings"
93            },
94            Self::TenantUnready { .. } => {
95                "Check the rollout in the cluster, then run 'systemprompt cloud status'"
96            },
97            Self::OperatorAuth { .. }
98            | Self::OperatorEndpoint { .. }
99            | Self::OperatorEmail { .. }
100            | Self::OperatorNotAuthenticated => {
101                "Run 'systemprompt cloud auth login --issuer <url> --client-id <id>'"
102            },
103        }
104    }
105
106    pub const fn requires_login(&self) -> bool {
107        matches!(
108            self,
109            Self::NotAuthenticated
110                | Self::TokenExpired
111                | Self::CredentialsCorrupted { .. }
112                | Self::Unauthorized
113        )
114    }
115}