Skip to content

Commit

Permalink
fix: Remove scoring panic.
Browse files Browse the repository at this point in the history
There was a `panic` call in some scoring code that meant we would
panic if we hit an error evaluating a policy expression instead of
returning it nicely. This converts that error into a nicer one.

Signed-off-by: Andrew Lilley Brinker <[email protected]>
  • Loading branch information
alilleybrinker committed Sep 10, 2024
1 parent 8b172b1 commit 7ab7c41
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions hipcheck/src/analysis/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,19 +491,18 @@ pub fn score_results(_phase: &SpinnerPhase, db: &dyn ScoringProvider) -> Result<
analysis.0.query.clone(),
target_json.clone(),
);

// Determine if analysis passed by evaluating policy expr
let passed = {
if let Ok(output) = &response {
match Executor::std().run(analysis.1.as_str(), &output.value) {
Ok(r) => r,
Err(e) => {
panic!("policy evaluation failed: {e}");
}
}
Executor::std()
.run(analysis.1.as_str(), &output.value)
.map_err(|e| hc_error!("{}", e))?
} else {
false
}
};

// Record in output map
plugin_results.table.insert(
analysis.0.clone(),
Expand Down

0 comments on commit 7ab7c41

Please sign in to comment.