1use bitwarden_error::bitwarden_error;
2use thiserror::Error;
3
4use crate::rpc::error::RpcError;
5
6pub trait IpcErrorKind {
23 fn is_fatal(&self) -> bool;
26}
27
28impl IpcErrorKind for std::convert::Infallible {
29 fn is_fatal(&self) -> bool {
30 match *self {}
32 }
33}
34
35#[cfg(any(test, feature = "test-support"))]
36impl IpcErrorKind for () {
37 fn is_fatal(&self) -> bool {
38 false
39 }
40}
41
42#[derive(Debug, Error, Clone, PartialEq, Eq)]
45#[error("IPC client is already running")]
46#[bitwarden_error(basic)]
47pub struct AlreadyRunningError;
48
49#[derive(Debug, Error, Clone, PartialEq, Eq)]
52#[error("{0}")]
53pub struct SendError(pub(crate) String);
54
55#[derive(Debug, Error, Clone, PartialEq, Eq)]
56#[bitwarden_error(flat)]
57#[allow(missing_docs)]
58pub enum SubscribeError {
59 #[error("The IPC processing thread is not running")]
60 NotStarted,
61}
62
63#[derive(Debug, Error, PartialEq, Eq)]
64#[bitwarden_error(flat)]
65#[allow(missing_docs)]
66pub enum ReceiveError {
67 #[error("Failed to subscribe to the IPC channel: {0}")]
68 Channel(#[from] tokio::sync::broadcast::error::RecvError),
69
70 #[error("Timed out while waiting for a message: {0}")]
71 Timeout(#[from] bitwarden_threading::time::ElapsedError),
72
73 #[error("Cancelled while waiting for a message")]
74 Cancelled,
75}
76
77#[derive(Debug, Error, PartialEq, Eq)]
78#[bitwarden_error(flat)]
79#[allow(missing_docs)]
80pub enum TypedReceiveError {
81 #[error("Failed to subscribe to the IPC channel: {0}")]
82 Channel(#[from] tokio::sync::broadcast::error::RecvError),
83
84 #[error("Timed out while waiting for a message: {0}")]
85 Timeout(#[from] bitwarden_threading::time::ElapsedError),
86
87 #[error("Cancelled while waiting for a message")]
88 Cancelled,
89
90 #[error("Typing error: {0}")]
91 Typing(String),
92}
93
94impl From<ReceiveError> for TypedReceiveError {
95 fn from(value: ReceiveError) -> Self {
96 match value {
97 ReceiveError::Channel(e) => TypedReceiveError::Channel(e),
98 ReceiveError::Timeout(e) => TypedReceiveError::Timeout(e),
99 ReceiveError::Cancelled => TypedReceiveError::Cancelled,
100 }
101 }
102}
103
104#[derive(Debug, Error, PartialEq, Eq)]
105#[bitwarden_error(flat)]
106#[allow(missing_docs)]
107pub enum RequestError {
108 #[error(transparent)]
109 Subscribe(#[from] SubscribeError),
110
111 #[error(transparent)]
112 Receive(#[from] TypedReceiveError),
113
114 #[error("Timed out while waiting for a message: {0}")]
115 Timeout(#[from] bitwarden_threading::time::ElapsedError),
116
117 #[error("Failed to send message: {0}")]
118 Send(String),
119
120 #[error("Error occurred on the remote target: {0}")]
121 Rpc(#[from] RpcError),
122}