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