1use crate::io::ParseError;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
7pub enum Error {
8 #[error("JSON serialization error: {0}")]
9 Json(#[from] serde_json::Error),
10
11 #[error("IO error: {0}")]
12 Io(#[from] std::io::Error),
13
14 #[error("Protocol error: {0}")]
15 Protocol(String),
16
17 #[error("Invalid message type: {0}")]
18 InvalidMessageType(String),
19
20 #[error("Missing required field: {0}")]
21 MissingField(String),
22
23 #[error("Invalid state transition: {0}")]
24 InvalidState(String),
25
26 #[error("Authorization code rejected: {message}")]
27 CodeRejected { message: String },
28
29 #[error(
30 "Timed out awaiting a login outcome; CLI screen content after submission:\n{transcript}"
31 )]
32 LoginTimeout { transcript: String },
33
34 #[error("Login CLI exited (code {code:?}) without a login outcome; output:\n{transcript}")]
46 LoginChildExited {
47 code: Option<u32>,
48 transcript: String,
49 },
50
51 #[error(
63 "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}"
64 )]
65 LoginExitUnverified {
66 logged_in: Option<bool>,
67 auth_method: Option<String>,
68 status_error: Option<String>,
69 transcript: String,
70 },
71
72 #[error("Timeout occurred")]
73 Timeout,
74
75 #[error("Connection closed")]
76 ConnectionClosed,
77
78 #[error("Deserialization error: {0}")]
79 Deserialization(#[from] ParseError),
80
81 #[error("Session UUID not yet available - no response received")]
82 SessionNotInitialized,
83
84 #[error("Binary not found: '{name}' is not on PATH. Is it installed?")]
85 BinaryNotFound { name: String },
86
87 #[error("Unknown error: {0}")]
88 Unknown(String),
89}
90
91pub type Result<T> = std::result::Result<T, Error>;