Skip to content

Commit

Permalink
Do not panic in Accumulator::drop() if we are already panicking
Browse files Browse the repository at this point in the history
  • Loading branch information
DCNick3 authored and TedDriggs committed Aug 24, 2022
1 parent b71b23e commit fad4cb7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/src/error/mod.rs
Expand Up @@ -683,10 +683,14 @@ impl Extend<Error> for Accumulator {

impl Drop for Accumulator {
fn drop(&mut self) {
if let Some(errors) = &mut self.0 {
match errors.len() {
0 => panic!("darling::error::Accumulator dropped without being finished"),
error_count => panic!("darling::error::Accumulator dropped without being finished. {} errors were lost.", error_count)
// don't try to panic if we are currently unwinding a panic
// otherwise we end up with an unhelful "thread panicked while panicking. aborting." message
if !std::thread::panicking() {
if let Some(errors) = &mut self.0 {
match errors.len() {
0 => panic!("darling::error::Accumulator dropped without being finished"),
error_count => panic!("darling::error::Accumulator dropped without being finished. {} errors were lost.", error_count)
}
}
}
}
Expand Down

0 comments on commit fad4cb7

Please sign in to comment.