systemprompt_cloud/credentials_bootstrap/
error.rs1use crate::error::CloudError;
8
9#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum CredentialsBootstrapError {
12 #[error("Credentials not initialized")]
13 NotInitialized,
14
15 #[error("Credentials already initialized")]
16 AlreadyInitialized,
17
18 #[error("Cloud credentials not available")]
19 NotAvailable,
20
21 #[error("Cloud credentials file not found: {path}")]
22 FileNotFound { path: String },
23
24 #[error("Cloud credentials file invalid: {message}")]
25 InvalidCredentials { message: String },
26
27 #[error("Cloud token has expired. Run 'systemprompt cloud login' to refresh")]
28 TokenExpired,
29
30 #[error("Cloud API validation failed: {message}")]
31 ApiValidationFailed { message: String },
32}
33
34impl CredentialsBootstrapError {
35 pub const fn is_file_not_found(&self) -> bool {
36 matches!(self, Self::FileNotFound { .. })
37 }
38}
39
40impl From<CredentialsBootstrapError> for CloudError {
41 fn from(value: CredentialsBootstrapError) -> Self {
42 match value {
43 CredentialsBootstrapError::NotInitialized => Self::CredentialsNotInitialized,
44 CredentialsBootstrapError::AlreadyInitialized => Self::CredentialsAlreadyInitialized,
45 CredentialsBootstrapError::NotAvailable => Self::NotAuthenticated,
46 CredentialsBootstrapError::FileNotFound { path } => {
47 Self::CredentialsFileNotFound { path }
48 },
49 CredentialsBootstrapError::InvalidCredentials { message } => {
50 Self::InvalidCredentials { message }
51 },
52 CredentialsBootstrapError::TokenExpired => Self::TokenExpired,
53 CredentialsBootstrapError::ApiValidationFailed { message } => {
54 Self::ApiValidationFailed { message }
55 },
56 }
57 }
58}