tree-wide: actually pretty-print error messages

We setup pretty-printing with all the thiserror-based Error structs, but
then only bubble the error up to the main, where it just gets printed
with the `Debug` trait.

This "catches" the error in the main and performs pretty printing using
the `Display` trait.

Before:

    Error: FailedCreatingListener(SocketError(Os { code: 98, kind:
        AddrInUse, message: "Address already in use" }))

After:

    [2023-07-06T17:20:47Z ERROR vhost_device_scsi] Failed creating
        listener: socket error: Address already in use (os error 98)

vhost-device-vsock is a bit special since it does not let error messages
bubble up to the main. It also does .unwrap() in most places, but it
_does_  pretty print errors during the main request handling part.

Had to slightly adjust the coverage since we have no tests for the main
functions.

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
This commit is contained in:
Erik Schilling 2023-07-06 19:09:01 +02:00 committed by Viresh Kumar
parent 8a1deef49a
commit 9332a933f8
6 changed files with 35 additions and 13 deletions

View File

@ -1,5 +1,5 @@
{
"coverage_score": 69.6,
"coverage_score": 69.0,
"exclude_path": "",
"crate_features": ""
}

View File

@ -5,8 +5,9 @@
//
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
use log::{info, warn};
use log::{error, info, warn};
use std::num::ParseIntError;
use std::process::exit;
use std::sync::{Arc, RwLock};
use std::thread::spawn;
@ -184,10 +185,13 @@ fn start_backend<D: 'static + GpioDevice + Send + Sync>(args: GpioArgs) -> Resul
Ok(())
}
pub(crate) fn gpio_init() -> Result<()> {
pub(crate) fn gpio_init() {
env_logger::init();
start_backend::<PhysDevice>(GpioArgs::parse())
if let Err(e) = start_backend::<PhysDevice>(GpioArgs::parse()) {
error!("{e}");
exit(1);
}
}
#[cfg(test)]

View File

@ -13,7 +13,7 @@ mod gpio;
mod vhu_gpio;
#[cfg(target_env = "gnu")]
fn main() -> backend::Result<()> {
fn main() {
backend::gpio_init()
}

View File

@ -8,8 +8,9 @@
mod i2c;
mod vhu_i2c;
use log::{info, warn};
use log::{error, info, warn};
use std::num::ParseIntError;
use std::process::exit;
use std::sync::{Arc, RwLock};
use std::thread::spawn;
@ -233,10 +234,13 @@ fn start_backend<D: 'static + I2cDevice + Send + Sync>(args: I2cArgs) -> Result<
Ok(())
}
fn main() -> Result<()> {
fn main() {
env_logger::init();
start_backend::<PhysDevice>(I2cArgs::parse())
if let Err(e) = start_backend::<PhysDevice>(I2cArgs::parse()) {
error!("{e}");
exit(1);
}
}
#[cfg(test)]

View File

@ -5,8 +5,9 @@
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
mod vhu_rng;
use log::{info, warn};
use log::{error, info, warn};
use std::fs::File;
use std::process::exit;
use std::sync::{Arc, Mutex, RwLock};
use std::thread;
@ -161,10 +162,13 @@ pub(crate) fn start_backend(config: VuRngConfig) -> Result<()> {
Ok(())
}
fn main() -> Result<()> {
fn main() {
env_logger::init();
start_backend(VuRngConfig::try_from(RngArgs::parse()).unwrap())
if let Err(e) = start_backend(VuRngConfig::try_from(RngArgs::parse()).unwrap()) {
error!("{e}");
exit(1);
}
}
#[cfg(test)]

View File

@ -7,6 +7,7 @@ mod virtio;
use std::{
fs::File,
path::PathBuf,
process::exit,
sync::{Arc, RwLock},
};
@ -126,11 +127,20 @@ fn start_backend(backend: VhostUserScsiBackend, args: ScsiArgs) -> Result<()> {
Ok(())
}
fn main() -> Result<()> {
fn run() -> Result<()> {
env_logger::init();
let args = ScsiArgs::parse();
let backend = create_backend(&args)?;
start_backend(backend, args)
start_backend(backend, args)?;
Ok(())
}
fn main() {
if let Err(e) = run() {
error!("{e}");
exit(1);
}
}
#[cfg(test)]