Skip to content

Commit

Permalink
runtime: panic if unhandled_panic is enabled when not supported (#6410
Browse files Browse the repository at this point in the history
)
  • Loading branch information
maminrayej committed Mar 20, 2024
1 parent 5baa8d5 commit d51f168
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tokio/src/runtime/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,10 @@ impl Builder {
/// will immediately terminate and further calls to
/// [`Runtime::block_on`] will panic.
///
/// # Panics
/// This method panics if called with [`UnhandledPanic::ShutdownRuntime`]
/// on a runtime other than the current thread runtime.
///
/// # Unstable
///
/// This option is currently unstable and its implementation is
Expand Down Expand Up @@ -861,6 +865,10 @@ impl Builder {
///
/// [`JoinHandle`]: struct@crate::task::JoinHandle
pub fn unhandled_panic(&mut self, behavior: UnhandledPanic) -> &mut Self {
if !matches!(self.kind, Kind::CurrentThread) && matches!(behavior, UnhandledPanic::ShutdownRuntime) {
panic!("UnhandledPanic::ShutdownRuntime is only supported in current thread runtime");
}

self.unhandled_panic = behavior;
self
}
Expand Down

0 comments on commit d51f168

Please sign in to comment.