Skip to content

Commit

Permalink
Make CLI more resilient for platform protocol errors (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 authored Oct 18, 2024
1 parent c967655 commit 7d5d944
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/cli-tools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Minor

- Handle more errors during platform discovery and `action::PlatformReboot`
- Extend `fs::write()` first parameter to set the `OpenOptions` too
- Add `error::root_cause_is()` to check the `anyhow::Error` root cause
- Add `action::PlatformLock` for locking a platform protocol
Expand Down
5 changes: 4 additions & 1 deletion crates/cli-tools/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,10 @@ async fn final_call<S: service::Service>(
match connection.receive::<S>().await {
Ok(x) => proof(x)?,
Err(e) => {
if root_cause_is::<rusb::Error>(&e, |x| matches!(x, rusb::Error::NoDevice)) {
if root_cause_is::<rusb::Error>(&e, |x| {
use rusb::Error::*;
matches!(x, NoDevice | Pipe)
}) {
return Ok(());
}
if root_cause_is::<std::io::Error>(&e, |x| {
Expand Down
4 changes: 2 additions & 2 deletions crates/cli-tools/src/action/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl ProtocolUsb {
let context = GlobalContext::default();
let mut matches = Vec::new();
for candidate in wasefire_protocol_usb::list(&context)? {
let mut connection = candidate.connect(timeout)?;
let info = connection.call::<service::PlatformInfo>(()).await?;
let Ok(mut connection) = candidate.connect(timeout) else { continue };
let Ok(info) = connection.call::<service::PlatformInfo>(()).await else { continue };
if !self.matches(connection.device(), &info) {
continue;
}
Expand Down

0 comments on commit 7d5d944

Please sign in to comment.