Skip to content

Commit

Permalink
fix: uglify logging in protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Nov 25, 2023
1 parent 8aa1ea4 commit e6980a5
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions ledger/src/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
use cfg_if::cfg_if;

use crate::{Ledger, LedgerError};

cfg_if!(
if #[cfg(target_arch = "wasm32")] {
use log::error;
} else {
use tracing::error;
}
);

/// A Ledger protocol. A Protocol communicates with the device to perform
/// A Ledger Recovery. A the device to perform
/// some operation. Protocols are run in a task, and may send multiple
/// commands to the device, and receive multiple responses. The protocol has
/// exclusive access to the transport while it is running.
Expand Down Expand Up @@ -43,9 +33,17 @@ pub trait LedgerProtocol {
match self.execute(transport) {
Ok(output) => Ok(output),
Err(e) => {
// TODO: make less ugly
#[cfg(target_arch = "wasm32")]
log::error!("Protocol failed, running recovery: {}", e);
#[cfg(not(target_arch = "wasm32"))]
tracing::error!(err = %e, "Protocol failed, running recovery.");

if let Err(e) = self.recover(transport) {
error!(err = %e, "Protocol recovery failed.");
#[cfg(target_arch = "wasm32")]
log::error!("Recovery failed: {}", e);
#[cfg(not(target_arch = "wasm32"))]
tracing::error!(err = %e, "Recovery failed.");
}

Err(e)
Expand Down

0 comments on commit e6980a5

Please sign in to comment.