diff options
author | David Tolnay <dtolnay@chromium.org> | 2019-02-12 17:51:26 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-02-20 08:20:02 -0800 |
commit | b4bd00fdad094b16c785b8ead9f92d68264f5fb4 (patch) | |
tree | 540ad033c789aa08a1ffed17e9c161df331600d2 /devices/src/pci/ac97_bus_master.rs | |
parent | 0373b9f154b5ec1894138b7c10ad495fcce7b64f (diff) | |
download | crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.gz crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.bz2 crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.lz crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.xz crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.zst crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.zip |
error: Print errors using Display impl
I have been running into Debug-printed error messages too often and needing to look up in the source code each level of nested errors to find out from the comment on the error variant what the short name of the variant means in human terms. Worse, many errors (like the one shown below) already had error strings written but were being printed from the calling code in the less helpful Debug representation anyway. Before: [ERROR:src/main.rs:705] The architecture failed to build the vm: NoVarEmpty After: [ERROR:src/main.rs:705] The architecture failed to build the vm: /var/empty doesn't exist, can't jail devices. TEST=cargo check --all-features TEST=FEATURES=test emerge-amd64-generic crosvm Change-Id: I77122c7d6861b2d610de2fff718896918ab21e10 Reviewed-on: https://chromium-review.googlesource.com/1469225 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'devices/src/pci/ac97_bus_master.rs')
-rw-r--r-- | devices/src/pci/ac97_bus_master.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/devices/src/pci/ac97_bus_master.rs b/devices/src/pci/ac97_bus_master.rs index 190fdce..b67450e 100644 --- a/devices/src/pci/ac97_bus_master.rs +++ b/devices/src/pci/ac97_bus_master.rs @@ -82,17 +82,15 @@ impl Error for PlaybackError {} impl Display for PlaybackError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use self::PlaybackError::*; + match self { - PlaybackError::ReadingGuestBufferAddress(e) => { - write!(f, "Failed to get the address of the audio buffer: {:?}.", e) - } - PlaybackError::ReadingGuestSamples(e) => { - write!(f, "Failed to read samples from guest memory: {:?}.", e) - } - PlaybackError::StreamError(e) => { - write!(f, "Failed to get a buffer from the stream: {:?}", e) + ReadingGuestBufferAddress(e) => { + write!(f, "Failed to get the address of the audio buffer: {}.", e) } - PlaybackError::WritingOutput(e) => write!(f, "Failed to write audio output: {:?}.", e), + ReadingGuestSamples(e) => write!(f, "Failed to read samples from guest memory: {}.", e), + StreamError(e) => write!(f, "Failed to get a buffer from the stream: {}", e), + WritingOutput(e) => write!(f, "Failed to write audio output: {}.", e), } } } @@ -151,8 +149,8 @@ impl Ac97BusMaster { loop { if let Err(e) = irq_resample_evt.read() { error!( - "Failed to read the irq event from the resample thread: {:?}.", - e + "Failed to read the irq event from the resample thread: {}.", + e, ); break; } @@ -163,7 +161,7 @@ impl Ac97BusMaster { if regs.func_regs(Ac97Function::Output).sr & int_mask != 0 { if let Some(irq_evt) = regs.irq_evt.as_ref() { if let Err(e) = irq_evt.write(1) { - error!("Failed to set the irq from the resample thread: {:?}.", e); + error!("Failed to set the irq from the resample thread: {}.", e); break; } } @@ -440,7 +438,7 @@ impl Ac97BusMaster { if let Err(e) = audio_out_thread(thread_regs, thread_mem, &thread_run, output_stream) { - error!("Playback error: {:?}", e); + error!("Playback error: {}", e); } thread_run.store(false, Ordering::Relaxed); })); |