Skip to main content

systemprompt_cloud/credentials_bootstrap/
error.rs

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