From 6d93afd3363db4e7da427a90e91c0fa66ab0bba3 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Fri, 27 Nov 2026 13:56:05 -0800 Subject: [PATCH 1/2] feat: propagate panics with `resume_unwind` This way, when we propagate a spawned task's panic, we get the original panic message, instead of the generic "Failed to join task" from `expect`. --- src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7258e74..685260c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use std::future::Future; +use tokio::task::JoinError; use tokio::task::JoinSet; /// The default number of parallel tasks used by [ParallelTaskSet]. @@ -190,7 +191,7 @@ impl ParallelTaskSet { /// /// This method panics if the task returns a JoinError pub async fn join_next(&mut self) -> Option { - self.set.join_next().await.map(|r| r.expect("Failed to join task")) + self.set.join_next().await.map(unwrap_join_result) } /// Returns the output of a task that has completed, if there are any such @@ -209,7 +210,7 @@ impl ParallelTaskSet { /// /// [`join_next`]: Self::join_next pub fn try_join_next(&mut self) -> Option { - self.set.try_join_next().map(|r| r.expect("Failed to join task")) + self.set.try_join_next().map(unwrap_join_result) } /// Wait for all remaining tasks to complete and return their output. @@ -311,6 +312,13 @@ where } } +fn unwrap_join_result(result: Result) -> T { + match result { + Ok(output) => output, + Err(err) => std::panic::resume_unwind(err.into_panic()), + } +} + #[cfg(test)] mod test { use super::*; From 50e8dd58b00317e911719301bb049cbabae65996 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 30 Nov 2026 15:08:59 -0800 Subject: [PATCH 2/2] remove mentions of JoinError --- src/lib.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 685260c..989de8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -158,8 +158,9 @@ impl ParallelTaskSet { /// /// # Panics /// - /// This method panics if it must await the completion of a currently - /// running task, and that task returns a [`tokio::task::JoinError`]. + /// If this method must await the completion of a currently running task, + /// and that task has panicked, this method propagates the panic (i.e. by + /// panicking itself with the same message as the panicked task). /// /// [`max_parallelism`]: ParallelTaskSet#limiting-parallelism /// [`join_next()`]: Self::join_next @@ -189,7 +190,9 @@ impl ParallelTaskSet { /// /// # Panics /// - /// This method panics if the task returns a JoinError + /// If the next completed task has panicked, this method propagates the + /// panic (i.e. by panicking itself with the same message as the panicked + /// task). pub async fn join_next(&mut self) -> Option { self.set.join_next().await.map(unwrap_join_result) } @@ -205,8 +208,9 @@ impl ParallelTaskSet { /// /// # Panics /// - /// This method panics if the next completed task has returned a - /// [`tokio::task::JoinError`]. + /// If the next completed task has panicked, this method propagates the + /// panic (i.e. by panicking itself with the same message as the panicked + /// task). /// /// [`join_next`]: Self::join_next pub fn try_join_next(&mut self) -> Option { @@ -221,7 +225,9 @@ impl ParallelTaskSet { /// /// # Panics /// - /// This method panics any of the tasks return a JoinError + /// If any of the remaining tasks have panicked, this method propagates the + /// panic (i.e. by panicking itself with the same message as the panicked + /// task). pub async fn join_remaining(self) -> Vec { self.set.join_all().await }