kitty_graphics_protocol/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
10pub enum Error {
11 #[error("Base64 decoding error: {0}")]
13 Base64Decode(#[from] base64::DecodeError),
14
15 #[error("Invalid image dimensions: width={width}, height={height}")]
17 InvalidDimensions { width: u32, height: u32 },
18
19 #[error("Invalid image ID: {0}")]
21 InvalidImageId(u32),
22
23 #[error("Invalid placement ID: {0}")]
25 InvalidPlacementId(u32),
26
27 #[error("Invalid chunk size: {0} (must be multiple of 4, max 4096)")]
29 InvalidChunkSize(usize),
30
31 #[error("Missing required field: {0}")]
33 MissingField(&'static str),
34
35 #[error("Terminal error: {0}")]
37 TerminalError(String),
38
39 #[error("IO error: {0}")]
41 Io(#[from] std::io::Error),
42
43 #[error("UTF-8 error: {0}")]
45 Utf8(#[from] std::string::FromUtf8Error),
46
47 #[error("UTF-8 error: {0}")]
49 Utf8Error(#[from] std::str::Utf8Error),
50
51 #[error("Invalid response from terminal: {0}")]
53 InvalidResponse(String),
54
55 #[error("Protocol error: {0}")]
57 Protocol(String),
58}
59
60impl Error {
61 pub fn protocol(msg: impl Into<String>) -> Self {
63 Self::Protocol(msg.into())
64 }
65
66 pub fn terminal(msg: impl Into<String>) -> Self {
68 Self::TerminalError(msg.into())
69 }
70}