Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Better error message for end users #1100

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading