ctb_workspace_ipc/
error.rs1#[allow(
23 unused_imports,
24 clippy::wildcard_imports,
25 reason = "Standard workspace prelude"
26)]
27use crate::utilities::*;
28
29use std::ffi::OsString;
30
31use thiserror::Error;
32
33use crate::protocol::Response;
34
35#[derive(Debug, Error)]
37pub enum Error {
38 #[error("Transport error: {0}")]
39 Transport(String),
40 #[error("Serialization error: {0}")]
41 Serialization(String),
42 #[error("Authorization error: {0}")]
43 Authorization(String),
44 #[error("Capability denied: {0}")]
45 CapabilityDenied(String),
46 #[error("Process error: {0}")]
47 Process(String),
48 #[error("Timeout")]
49 Timeout,
50 #[error("Canceled")]
51 Canceled,
52 #[error("Not found")]
53 NotFound,
54 #[error("Unsupported: {0}")]
55 Unsupported(String),
56 #[error("Internal: {0}")]
57 Internal(String),
58}
59
60impl From<std::io::Error> for Error {
61 fn from(e: std::io::Error) -> Self {
63 Error::Transport(e.to_string())
64 }
65}
66
67impl From<anyhow::Error> for Error {
68 fn from(e: anyhow::Error) -> Self {
70 Error::Internal(e.to_string())
71 }
72}
73
74impl From<std::num::TryFromIntError> for Error {
75 fn from(e: std::num::TryFromIntError) -> Self {
76 Error::Internal(e.to_string())
77 }
78}
79
80impl From<crate::protocol::RpcError> for Error {
81 fn from(e: crate::protocol::RpcError) -> Self {
82 Error::Internal(format!("RPC error {}: {}", e.code, e.message))
83 }
84}
85
86impl From<Response> for Error {
87 fn from(resp: Response) -> Self {
89 match resp.error {
90 Some(error) => Error::from(error),
91 _ => Error::Internal("Expected error response".to_string()),
92 }
93 }
94}
95
96impl From<OsString> for Error {
97 fn from(e: OsString) -> Self {
98 Error::Internal(format!("OS string error: {e:?}"))
99 }
100}
101
102pub(crate) fn to_ipc_error(e: anyhow::Error) -> Error {
104 e.into()
105}