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::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 auth login' to authenticate"
43            },
44            Self::JwtDecode | Self::CredentialsCorrupted { .. } => {
45                "Run 'systemprompt cloud auth login' to re-authenticate"
46            },
47            Self::TenantsNotSynced
48            | Self::TenantsStoreCorrupted { .. }
49            | Self::TenantsStoreInvalid { .. } => {
50                "Run 'systemprompt cloud auth login' to sync tenants"
51            },
52            Self::ApiError { .. } | Self::HttpStatus { .. } | Self::ApiValidationFailed { .. } => {
53                "Check the error message and try again"
54            },
55            Self::Network(_) => "Check your internet connection and try again",
56            Self::Io(_) => "Check file permissions and disk space",
57            Self::Json(_) => "Inspect the JSON file referenced in the error message",
58            Self::InvalidCredentials { .. } | Self::CredentialsFileNotFound { .. } => {
59                "Run 'systemprompt cloud auth login' to refresh credentials"
60            },
61            Self::CredentialsNotInitialized | Self::CredentialsAlreadyInitialized => {
62                "Restart the process to re-run the bootstrap sequence"
63            },
64            Self::SessionVersionMismatch { .. } => "Delete the session file and re-authenticate",
65            Self::SessionStoreCorrupted { .. } => {
66                "Run 'systemprompt admin session switch <profile>' to reset the session store"
67            },
68            Self::OAuthFlow { .. } => "Re-run the OAuth login flow",
69            Self::Dockerfile { .. } => {
70                "Regenerate the Dockerfile with 'systemprompt cloud profile create'"
71            },
72            Self::Docker { .. } => "Check that Docker is installed and running",
73            Self::Deploy { .. } | Self::Other { .. } => "Inspect the error message and try again",
74        }
75    }
76
77    pub const fn requires_login(&self) -> bool {
78        matches!(
79            self,
80            Self::NotAuthenticated
81                | Self::TokenExpired
82                | Self::CredentialsCorrupted { .. }
83                | Self::Unauthorized
84        )
85    }
86}