1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Error types for the Claude Code protocol
use crate::io::ParseError;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("JSON serialization error: {0}")]
Json(#[from] serde_json::Error),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Protocol error: {0}")]
Protocol(String),
#[error("Invalid message type: {0}")]
InvalidMessageType(String),
#[error("Missing required field: {0}")]
MissingField(String),
#[error("Invalid state transition: {0}")]
InvalidState(String),
#[error("Authorization code rejected: {message}")]
CodeRejected { message: String },
#[error(
"Timed out awaiting a login outcome; CLI screen content after submission:\n{transcript}"
)]
LoginTimeout { transcript: String },
/// The login CLI process exited without producing a login outcome.
///
/// Reading `code` (signal deaths surface as `128 + signo`):
/// - `0` / small integers — the CLI exited on its own (its error text,
/// if any, is in `transcript`).
/// - `143` (SIGTERM) — terminated externally, OR the host application
/// dropped the `LoginFlow` mid-flight (the crate's `Drop` kills with
/// SIGTERM and, with the `log` feature, warns
/// "LoginFlow dropped while unfinished" — check logs to attribute).
/// - `137` (SIGKILL) — killed externally (OOM killer, `kill -9`); the
/// crate never sends SIGKILL.
#[error("Login CLI exited (code {code:?}) without a login outcome; output:\n{transcript}")]
LoginChildExited {
code: Option<u32>,
transcript: String,
},
/// The login CLI exited cleanly (code 0) without an observed credentials
/// write, and `claude auth status` did not confirm a login of the flow's
/// kind. Not proof the login failed — completion just couldn't be
/// verified.
///
/// - `logged_in` / `auth_method` — what the status reported; `None` when
/// the status check itself failed (see `status_error`). `logged_in:
/// Some(false)` means signed out; `Some(true)` with another
/// `auth_method` means a different credential kind is active.
/// - `status_error` — why the status check failed (spawn error, timeout,
/// unparseable output).
#[error(
"Login CLI exited cleanly but the login could not be verified (logged_in: {logged_in:?}, auth_method: {auth_method:?}, status_error: {status_error:?}); output:\n{transcript}"
)]
LoginExitUnverified {
logged_in: Option<bool>,
auth_method: Option<String>,
status_error: Option<String>,
transcript: String,
},
#[error("Timeout occurred")]
Timeout,
#[error("Connection closed")]
ConnectionClosed,
#[error("Deserialization error: {0}")]
Deserialization(#[from] ParseError),
#[error("Session UUID not yet available - no response received")]
SessionNotInitialized,
#[error("Binary not found: '{name}' is not on PATH. Is it installed?")]
BinaryNotFound { name: String },
#[error("Unknown error: {0}")]
Unknown(String),
}
pub type Result<T> = std::result::Result<T, Error>;