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: {source}")]
25 InvalidCredentials {
26 #[source]
27 source: Box<CloudError>,
28 },
29
30 #[error("Cloud token has expired. Run 'systemprompt cloud auth login' to refresh")]
31 TokenExpired,
32
33 #[error("Cloud API validation failed: {message}: {source}")]
34 ApiValidationFailed {
35 message: String,
36 #[source]
37 source: Box<CloudError>,
38 },
39}
40
41impl CredentialsBootstrapError {
42 pub const fn is_file_not_found(&self) -> bool {
43 matches!(self, Self::FileNotFound { .. })
44 }
45}
46
47impl From<CredentialsBootstrapError> for CloudError {
48 fn from(value: CredentialsBootstrapError) -> Self {
49 match value {
50 CredentialsBootstrapError::NotInitialized => Self::CredentialsNotInitialized,
51 CredentialsBootstrapError::AlreadyInitialized => Self::CredentialsAlreadyInitialized,
52 CredentialsBootstrapError::NotAvailable => Self::NotAuthenticated,
53 CredentialsBootstrapError::FileNotFound { path } => {
54 Self::CredentialsFileNotFound { path }
55 },
56 CredentialsBootstrapError::InvalidCredentials { source } => {
57 Self::InvalidCredentials { source }
58 },
59 CredentialsBootstrapError::TokenExpired => Self::TokenExpired,
60 CredentialsBootstrapError::ApiValidationFailed { message, source } => {
61 Self::ApiValidationFailed { message, source }
62 },
63 }
64 }
65}