From 55f7f2a50d6e560fc712c18972fa5b1d11525ffb Mon Sep 17 00:00:00 2001 From: Rain Date: Thu, 21 Sep 2023 15:14:15 -0700 Subject: [PATCH] [nextest-runner] on exec fail, stash error into stderr A bit of a hack but a thoughtful one. --- Cargo.lock | 7 +++++++ nextest-runner/Cargo.toml | 1 + nextest-runner/src/runner.rs | 25 ++++++++++++++++--------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c0b8d8538b..0d80d490c32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -592,6 +592,12 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "display-error-chain" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f77af9e75578c1ab34f5f04545a8b05be0c36fbd7a9bb3cf2d2a971e435fdbb9" + [[package]] name = "duct" version = "0.13.6" @@ -1526,6 +1532,7 @@ dependencies = [ "config", "console-subscriber", "debug-ignore", + "display-error-chain", "duct", "dunce", "either", diff --git a/nextest-runner/Cargo.toml b/nextest-runner/Cargo.toml index 1f651ed6ead..f35f738ff46 100644 --- a/nextest-runner/Cargo.toml +++ b/nextest-runner/Cargo.toml @@ -24,6 +24,7 @@ cargo_metadata = "0.17.0" cfg-if = "1.0.0" chrono = "0.4.31" debug-ignore = "1.0.5" +display-error-chain = "0.2.0" either = "1.9.0" futures = "0.3.28" guppy = "0.17.1" diff --git a/nextest-runner/src/runner.rs b/nextest-runner/src/runner.rs index 43fe92a4971..ee85614c116 100644 --- a/nextest-runner/src/runner.rs +++ b/nextest-runner/src/runner.rs @@ -19,12 +19,14 @@ use crate::{ }; use async_scoped::TokioScope; use bytes::Bytes; +use display_error_chain::DisplayErrorChain; use future_queue::StreamExt; use futures::{future::try_join, prelude::*}; use nextest_metadata::{FilterMatch, MismatchReason}; use rand::{distributions::OpenClosed01, thread_rng, Rng}; use std::{ convert::Infallible, + fmt::Write, marker::PhantomData, num::NonZeroUsize, process::Stdio, @@ -628,15 +630,20 @@ impl<'a> TestRunnerInner<'a> { .await { Ok(run_status) => run_status, - Err(_) => InternalExecuteStatus { - // TODO: can we return more information in stdout/stderr? investigate this - stdout: Bytes::new(), - stderr: Bytes::new(), - result: ExecutionResult::ExecFail, - stopwatch_end: stopwatch.end(), - is_slow: false, - delay_before_start, - }, + Err(error) => { + // Put the error chain inside stderr. + let mut stderr = bytes::BytesMut::new(); + writeln!(&mut stderr, "{}", DisplayErrorChain::new(error)).unwrap(); + + InternalExecuteStatus { + stdout: Bytes::new(), + stderr: stderr.freeze(), + result: ExecutionResult::ExecFail, + stopwatch_end: stopwatch.end(), + is_slow: false, + delay_before_start, + } + } } }