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("Timeout occurred")]
52 Timeout,
53
54 #[error("Connection closed")]
55 ConnectionClosed,
56
57 #[error("Deserialization error: {0}")]
58 Deserialization(#[from] ParseError),
59
60 #[error("Session UUID not yet available - no response received")]
61 SessionNotInitialized,
62
63 #[error("Binary not found: '{name}' is not on PATH. Is it installed?")]
64 BinaryNotFound { name: String },
65
66 #[error("Unknown error: {0}")]
67 Unknown(String),
68}
69
70pub type Result<T> = std::result::Result<T, Error>;