Skip to content

Commit

Permalink
chore: remove unwrap()
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Mar 8, 2024
1 parent beef601 commit 9ff55a8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/importer/src/csaf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct ImportCsafCommand {

impl ImportCsafCommand {
pub async fn run(self) -> anyhow::Result<ExitCode> {
let progress = init_log_and_progress();
let progress = init_log_and_progress()?;

let system = InnerSystem::with_config(&self.database).await?;

Expand Down
9 changes: 5 additions & 4 deletions backend/importer/src/progress.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use anyhow::Context;
use indicatif::MultiProgress;
use indicatif_log_bridge::LogWrapper;
use std::io::IsTerminal;
use walker_common::progress::Progress;

/// Set up the env_logger and attach a progress interface if we are running on a terminal.
pub(crate) fn init_log_and_progress() -> Progress {
pub(crate) fn init_log_and_progress() -> anyhow::Result<Progress> {
let mut builder = env_logger::builder();
let logger = builder.build();

Expand All @@ -15,11 +16,11 @@ pub(crate) fn init_log_and_progress() -> Progress {

let log = LogWrapper::new(multi.clone(), logger);
// NOTE: LogWrapper::try_init is buggy and messes up the log levels
log::set_boxed_logger(Box::new(log)).unwrap();
log::set_boxed_logger(Box::new(log)).context("failed to initialize logger")?;
log::set_max_level(max_level);

multi.into()
Ok(multi.into())
}
false => Progress::default(),
false => Ok(Progress::default()),
}
}
2 changes: 1 addition & 1 deletion backend/importer/src/sbom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct ImportSbomCommand {

impl ImportSbomCommand {
pub async fn run(self) -> anyhow::Result<ExitCode> {
let progress = init_log_and_progress();
let progress = init_log_and_progress()?;

log::info!("Ingesting SBOMs");

Expand Down

0 comments on commit 9ff55a8

Please sign in to comment.