Skip to content

Commit

Permalink
Return Message::Failure to SSH client to gracefully inform about error
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
wiktor-k committed Mar 12, 2024
1 parent ed1635d commit c08cb6b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c08cb6b

Please sign in to comment.