Skip to content

Commit

Permalink
Rework joiner_token unhandled stopreason handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Oct 22, 2023
1 parent b666d26 commit 7a1cb77
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,18 @@ pub(crate) fn handle_dropped_error<ErrType: ErrTypeTraits>(
}
}

// This function contains code that stems from the principle
// of defensive coding - meaning, handle potential errors
// gracefully, even if they should not happen.
// Therefore it is in this special function, so we don't
// get coverage problems.
pub(crate) fn handle_unhandled_stopreason<ErrType: ErrTypeTraits>(
maybe_stop_reason: Option<SubsystemError<ErrType>>,
) {
if let Some(stop_reason) = maybe_stop_reason {
tracing::warn!("Unhandled stop reason: {:?}", stop_reason);
}
}

#[cfg(test)]
mod tests;
10 changes: 10 additions & 0 deletions src/errors/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,13 @@ fn handle_dropped_errors() {

assert!(logs_contain("An error got dropped: \"ABC\""));
}

#[test]
#[traced_test]
fn handle_unhandled_stopreasons() {
handle_unhandled_stopreason(Some(SubsystemError::<BoxedError>::Panicked(Arc::from(
"def",
))));

assert!(logs_contain("Unhandled stop reason: Panicked(\"def\")"));
}
9 changes: 5 additions & 4 deletions src/utils/joiner_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use std::{fmt::Debug, sync::Arc};

use tokio::sync::watch;

use crate::{errors::SubsystemError, ErrTypeTraits};
use crate::{
errors::{handle_unhandled_stopreason, SubsystemError},
ErrTypeTraits,
};

struct Inner<ErrType: ErrTypeTraits> {
counter: watch::Sender<(bool, u32)>,
Expand Down Expand Up @@ -126,9 +129,7 @@ impl<ErrType: ErrTypeTraits> JoinerToken<ErrType> {
maybe_parent = parent.parent.as_ref();
}

if let Some(stop_reason) = maybe_stop_reason {
tracing::warn!("Unhandled stop reason: {:?}", stop_reason);
}
handle_unhandled_stopreason(maybe_stop_reason);
}

pub(crate) fn downgrade(self) -> JoinerTokenRef {
Expand Down

0 comments on commit 7a1cb77

Please sign in to comment.