entelix_auth_claude_code/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum ClaudeCodeAuthError {
13 #[error("Claude Code credentials not found at `{path}` — run `claude login` first")]
16 CredentialsMissing {
17 path: String,
19 },
20 #[error("Claude Code credential file `{path}` has no OAuth section")]
22 OAuthSectionMissing {
23 path: String,
25 },
26 #[error("Claude Code OAuth refresh token absent — re-authenticate via `claude login`")]
29 RefreshTokenMissing,
30 #[error("Claude Code OAuth refresh failed: {message}")]
32 RefreshHttp {
33 message: String,
36 },
37 #[error("Claude Code credential file `{path}` is not valid JSON: {source}")]
39 InvalidStorage {
40 path: String,
42 #[source]
44 source: serde_json::Error,
45 },
46 #[error("Claude Code credential file `{path}` IO failed: {source}")]
48 Io {
49 path: String,
51 #[source]
53 source: std::io::Error,
54 },
55 #[error("home directory not resolvable — supply the credentials path explicitly")]
58 HomeUnresolved,
59}
60
61pub type ClaudeCodeAuthResult<T> = Result<T, ClaudeCodeAuthError>;
63
64impl From<ClaudeCodeAuthError> for entelix_core::Error {
65 fn from(err: ClaudeCodeAuthError) -> Self {
66 use entelix_core::auth::AuthError;
67 let message = err.to_string();
68 match err {
69 ClaudeCodeAuthError::CredentialsMissing { .. }
70 | ClaudeCodeAuthError::OAuthSectionMissing { .. }
71 | ClaudeCodeAuthError::HomeUnresolved => Self::Auth(AuthError::missing_from(message)),
72 ClaudeCodeAuthError::RefreshTokenMissing => {
73 Self::Auth(AuthError::expired_with(message))
74 }
75 ClaudeCodeAuthError::RefreshHttp { .. } => {
76 Self::Auth(AuthError::source_unreachable(message))
77 }
78 ClaudeCodeAuthError::InvalidStorage { .. } | ClaudeCodeAuthError::Io { .. } => {
79 Self::Auth(AuthError::refused(message))
80 }
81 }
82 }
83}