From c08cb6bfc466d9ce976a4236524242760406722e Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Tue, 12 Mar 2024 12:20:03 +0100 Subject: [PATCH] Return `Message::Failure` to SSH client to gracefully inform about error Without this change the client informs about error in communication: ``` $ ssh-add -s test Enter passphrase for PKCS#11: Could not add card "test": communication with agent failed ``` After this change the error informs about agent refusing the operation: ``` $ ssh-add -s test Enter passphrase for PKCS#11: Could not add card "test": agent refused operation ``` Signed-off-by: Wiktor Kwapisiewicz --- src/agent.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/agent.rs b/src/agent.rs index c894e1d..671a97b 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -88,10 +88,13 @@ pub trait Session: 'static + Sync + Send + Sized { { loop { if let Some(incoming_message) = adapter.try_next().await? { - let response = self.handle(incoming_message).await.map_err(|e| { - error!("Error handling message; error = {:?}", e); - AgentError::User - })?; + let response = match self.handle(incoming_message).await { + Ok(message) => message, + Err(e) => { + error!("Error handling message; error = {:?}", e); + Message::Failure + } + }; adapter.send(response).await?; } else {