Skip to main content

codex_auth_manager/
error.rs

1use std::path::PathBuf;
2
3use thiserror::Error;
4
5use super::{IdentityName, UnknownAuthReason};
6
7/// Error returned by the library API.
8#[derive(Debug, Error)]
9pub enum Error {
10    /// Environment did not contain enough information to resolve Codex home.
11    #[error("failed to determine Codex home: {source}")]
12    Env {
13        /// Source environment error.
14        source: std::env::VarError,
15    },
16    /// Current working directory could not be read while absolutizing a path.
17    #[error("failed to determine current directory: {source}")]
18    CurrentDir {
19        /// Source filesystem error.
20        source: std::io::Error,
21    },
22    /// Filesystem operation failed.
23    #[error("failed to {action} at {}: {source}", path.display())]
24    Io {
25        /// Action being attempted.
26        action: &'static str,
27        /// Path involved in the failure.
28        path: PathBuf,
29        /// Source filesystem error.
30        source: std::io::Error,
31    },
32    /// Identity name is invalid.
33    #[error("invalid identity name: {name}")]
34    InvalidIdentityName {
35        /// Invalid name.
36        name: String,
37    },
38    /// Identity does not exist.
39    #[error("identity not found: {name}")]
40    IdentityNotFound {
41        /// Missing identity name.
42        name: IdentityName,
43    },
44    /// Identity already exists.
45    #[error("identity already exists: {name}")]
46    IdentityAlreadyExists {
47        /// Existing identity name.
48        name: IdentityName,
49    },
50    /// Identity entry exists but is unusable.
51    #[error("identity is broken: {name}")]
52    IdentityBroken {
53        /// Broken identity name.
54        name: IdentityName,
55    },
56    /// Native auth file exists and would be discarded.
57    #[error("native auth file exists; capture it first or pass --force to discard it")]
58    NativeAuthExists,
59    /// No native auth file exists to capture.
60    #[error("no native auth file to capture")]
61    NoNativeAuthFile,
62    /// Codex home does not exist.
63    #[error("codex home missing: {}", path.display())]
64    CodexHomeMissing {
65        /// Missing Codex home path.
66        path: PathBuf,
67    },
68    /// Current auth state is unknown.
69    #[error("unknown auth state: {reason}")]
70    UnknownAuthState {
71        /// Reason the auth state is unknown.
72        reason: UnknownAuthReason,
73    },
74}