summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@sequoia-pgp.org>2024-03-06 10:14:44 +0100
committerNeal H. Walfield <neal@sequoia-pgp.org>2024-03-06 10:31:20 +0100
commitd0c536c11032bd5c86a4697ce44a0c1e3097916f (patch)
treeb00f44ae92424ae2e2e51bfbdb5081acc198ef35
parent01493ac231d746720ca0ff91eb0966bc126df75d (diff)
ipc: Don't panic if the server disappears, return an error.
- If the server exits, we set the connection's state to `WriteState::Dead`. - When sending a message, don't panic if the connection's state is `WriteState::Dead`. Instead, return an error message.
-rw-r--r--ipc/src/assuan/mod.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/ipc/src/assuan/mod.rs b/ipc/src/assuan/mod.rs
index 51cd0c87..47cb2298 100644
--- a/ipc/src/assuan/mod.rs
+++ b/ipc/src/assuan/mod.rs
@@ -75,6 +75,20 @@ enum WriteState {
}
assert_send_and_sync!(WriteState);
+impl std::fmt::Debug for WriteState {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>)
+ -> std::result::Result<(), std::fmt::Error>
+ {
+ use WriteState::*;
+ match self {
+ Ready(_) => write!(f, "WriteState::Ready"),
+ Sending(_) => write!(f, "WriteState::Sending"),
+ Transitioning => write!(f, "WriteState::Transitioning"),
+ Dead => write!(f, "WriteState::Dead"),
+ }
+ }
+}
+
/// Percent-escapes the given string.
pub fn escape<S: AsRef<str>>(s: S) -> String {
let mut r = String::with_capacity(s.as_ref().len());
@@ -147,7 +161,14 @@ impl Client {
Ok(sink)
}))
},
- _ => unreachable!(),
+ WriteState::Dead => {
+ // We're still dead.
+ self.w = WriteState::Dead;
+ return Err(crate::gnupg::Error::OperationFailed(
+ "Connection dropped".into()).into());
+ }
+ s => panic!("Client state machine desynchronized with servers: \
+ in {:?}, should be in WriteState::Ready", s),
};
Ok(())