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::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::SessionVersionMismatch { .. } => "CLI session file is out of date",
26            Self::SessionStoreCorrupted { .. } => "CLI session store is stale or corrupt",
27            Self::OAuthFlow { .. } => "OAuth login flow failed",
28            Self::Deploy { .. } => "Cloud deploy failed",
29            Self::Dockerfile { .. } => "Dockerfile validation failed",
30            Self::Docker { .. } => "Docker command failed",
31            Self::Unauthorized => "Cloud API rejected this token",
32            Self::HttpStatus { .. } => "Cloud API returned a non-success status",
33        }
34    }
35
36    pub const fn recovery_hint(&self) -> &'static str {
37        match self {
38            Self::NotAuthenticated | Self::TokenExpired | Self::Unauthorized => {
39                "Run 'systemprompt cloud auth login' to authenticate"
40            },
41            Self::JwtDecode | Self::CredentialsCorrupted { .. } => {
42                "Run 'systemprompt cloud auth login' to re-authenticate"
43            },
44            Self::TenantsNotSynced
45            | Self::TenantsStoreCorrupted { .. }
46            | Self::TenantsStoreInvalid { .. } => {
47                "Run 'systemprompt cloud auth login' to sync tenants"
48            },
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 auth login' to refresh credentials"
57            },
58            Self::SessionVersionMismatch { .. } => "Delete the session file and re-authenticate",
59            Self::SessionStoreCorrupted { .. } => {
60                "Run 'systemprompt admin session switch <profile>' to reset the session store"
61            },
62            Self::OAuthFlow { .. } => "Re-run the OAuth login flow",
63            Self::Dockerfile { .. } => {
64                "Regenerate the Dockerfile with 'systemprompt cloud profile create'"
65            },
66            Self::Docker { .. } => "Check that Docker is installed and running",
67            Self::Deploy { .. } => "Inspect the error message and try again",
68        }
69    }
70
71    pub const fn requires_login(&self) -> bool {
72        matches!(
73            self,
74            Self::NotAuthenticated
75                | Self::TokenExpired
76                | Self::CredentialsCorrupted { .. }
77                | Self::Unauthorized
78        )
79    }
80}