Skip to content

Commit

Permalink
feat: add method to retrieve Summary from Arc<Mutex> with error handling
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Nov 25, 2024
1 parent ddf7828 commit 4b3d073
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/core/src/error/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ use std::{

use ecow::EcoString;

use crate::error::{ErrorKind, RusticError, RusticResult};

pub type Issues = BTreeMap<IssueCategory, BTreeMap<IssueScope, CondensedIssue>>;

pub type Metrics = BTreeMap<EcoString, EcoString>;
Expand Down Expand Up @@ -302,6 +304,21 @@ impl Summary {
pub fn into_arc_mutex(self) -> Arc<Mutex<Self>> {
Arc::new(Mutex::new(self))
}

pub fn retrieve_from_arc_mutex(arc_mutex: Arc<Mutex<Summary>>) -> RusticResult<Self> {
Arc::try_unwrap(arc_mutex)
.map_err(|_err| {
RusticError::new(ErrorKind::Internal, "Error unwrapping Mutex from Arc.")
})?
.into_inner()
.map_err(|err| {
RusticError::with_source(
ErrorKind::Internal,
"Mutex poisoned while getting summary for check command.",
err,
)
})
}
}

// Display Helpers
Expand Down

0 comments on commit 4b3d073

Please sign in to comment.