How can I proxy a panic message from a thread pool to the test endpoint?

⚓ Rust    📅 2025-07-07    👤 surdeus    👁️ 4      

surdeus

I have some thread pool. It creates some async runner and executes a provided future. It also uses catch_unwind to catch panics. If a panic occurs, a thread from the pool shuts down and sends via a sync channel the caught data. The main test endpoint periodically checks all spawned (by this endpoint) handles and resume_unwind if it gets a panic. Like

pub(crate) type JobResult = thread::Result<()>;

pub(crate) struct ExecutorPoolJoinHandle {
    was_joined: bool,
    sync_receiver: SyncReceiver<JobResult>,
}


pub(crate) fn join_timeout_maybe_resume_panic(
        &mut self,
        timeout: Option<Duration>,
    ) -> Result<(), RecvTimeoutError>
    {
        assert!(!self.was_joined);

        let res = if let Some(timeout) = timeout {
            match self.sync_receiver.recv_timeout(timeout) {
                Ok(res) => res,
                Err(RecvTimeoutError::Timeout) => return Err(RecvTimeoutError::Timeout),
                _ => panic!("{BUG_MESSAGE}"),
            }
        } else {
            self.sync_receiver.recv().expect(BUG_MESSAGE)
        };

        self.was_joined = true;

        if let Err(err) = res {
            panic::resume_unwind(err);
        }

        Ok(())
    }

And it sees panics. It also fails tests. But in the RustRover test's window, I don't see the panic message. If I run it with the console, I can see something like it:

---- runtime::epoch_gc::test::test_epoch_gc_concurrent stdout ----
Test test_epoch_gc_concurrent started!

thread 'orengine-test-executor' panicked at src/runtime/epoch_gc/test.rs:116:9:
assertion left == right failed
left: 4
right: 24

Looks like all messages are forwarded to the stdout. How to forward them to the stderr?

3 posts - 3 participants

Read full topic

🏷️ rust_feed