Skip to content

Commit cf7a9ae

Browse files
authored
Rollup merge of #100040 - ChrisDenton:broken-pipe, r=davidtwco
Error on broken pipe but do not backtrace or ICE Windows will report a broken pipe as a normal error which in turn `println!` will panic on. Currently this causes rustc to produce a backtrace and ICE. However, this is not a bug with rustc so a backtrace is overly verbose and ultimately unhelpful to the user. Kind of fixes #98700. Although this is admittedly a bit of a hack because at panic time all we have is a string to inspect. On zulip it was suggested that libstd might someday provide a way to indicate a soft panic but that day isn't today.
2 parents 0dc39c7 + 27b9b16 commit cf7a9ae

File tree

1 file changed

+11
-0
lines changed
  • compiler/rustc_driver/src

1 file changed

+11
-0
lines changed

compiler/rustc_driver/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,17 @@ static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send +
11481148
LazyLock::new(|| {
11491149
let hook = panic::take_hook();
11501150
panic::set_hook(Box::new(|info| {
1151+
// If the error was caused by a broken pipe then this is not a bug.
1152+
// Write the error and return immediately. See #98700.
1153+
#[cfg(windows)]
1154+
if let Some(msg) = info.payload().downcast_ref::<String>() {
1155+
if msg.starts_with("failed printing to stdout: ") && msg.ends_with("(os error 232)")
1156+
{
1157+
early_error_no_abort(ErrorOutputType::default(), &msg);
1158+
return;
1159+
}
1160+
};
1161+
11511162
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
11521163
(*DEFAULT_HOOK)(info);
11531164

0 commit comments

Comments
 (0)