Skip to content

Commit

Permalink
chore: Better error message for end users
Browse files Browse the repository at this point in the history
  • Loading branch information
helio-frota committed Dec 13, 2024
1 parent c4a3768 commit f6d1c98
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
23 changes: 17 additions & 6 deletions modules/importer/src/runner/csaf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,23 @@ impl super::ImportRunner {
.await
// if the walker fails, we record the outcome as part of the report, but skip any
// further processing, like storing the marker
.map_err(|err| ScannerError::Normal {
err: err.into(),
output: RunOutput {
report: report.lock().clone().build(),
continuation: None,
},
.map_err(|err| {
// Formatted error for user (UI)
let err_string = err.to_string();
// Checks if the error message contains a custom prefix like `Visitor error:`
let formatted_err = if let Some(index) = err_string.find(':') {
format!("Error: {}", &err_string[index + 1..].trim_start())
} else {
format!("Error: {}", err_string)
};

ScannerError::Normal {
err: anyhow::Error::msg(formatted_err),
output: RunOutput {
report: report.lock().clone().build(),
continuation: None,
},
}
})?;

Ok(match Arc::try_unwrap(report) {
Expand Down
23 changes: 17 additions & 6 deletions modules/importer/src/runner/sbom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,23 @@ impl super::ImportRunner {
.await
// if the walker fails, we record the outcome as part of the report, but skip any
// further processing, like storing the marker
.map_err(|err| ScannerError::Normal {
err: err.into(),
output: RunOutput {
report: report.lock().clone().build(),
continuation: None,
},
.map_err(|err| {
// Formatted error for user (UI)
let err_string = err.to_string();
// Checks if the error message contains a custom prefix like `Visitor error:`
let formatted_err = if let Some(index) = err_string.find(':') {
format!("Error: {}", &err_string[index + 1..].trim_start())
} else {
format!("Error: {}", err_string)
};

ScannerError::Normal {
err: anyhow::Error::msg(formatted_err),
output: RunOutput {
report: report.lock().clone().build(),
continuation: None,
},
}
})?;

Ok(match Arc::try_unwrap(report) {
Expand Down

0 comments on commit f6d1c98

Please sign in to comment.