]> git.lizzy.rs Git - rust.git/commitdiff
Error on broken pipe but do not ICE
authorChris Denton <christophersdenton@gmail.com>
Tue, 2 Aug 2022 00:08:13 +0000 (01:08 +0100)
committerChris Denton <christophersdenton@gmail.com>
Tue, 2 Aug 2022 00:08:50 +0000 (01:08 +0100)
compiler/rustc_driver/src/lib.rs

index 53ae913f94f124f9dd1166c5eb723e177d21253b..94639bf8e1ee4f1d122cd6bf52e382d9e79d52dd 100644 (file)
@@ -1148,6 +1148,17 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
     LazyLock::new(|| {
         let hook = panic::take_hook();
         panic::set_hook(Box::new(|info| {
+            // If the error was caused by a broken pipe then this is not a bug.
+            // Write the error and return immediately. See #98700.
+            #[cfg(windows)]
+            if let Some(msg) = info.payload().downcast_ref::<String>() {
+                if msg.starts_with("failed printing to stdout: ") && msg.ends_with("(os error 232)")
+                {
+                    early_error_no_abort(ErrorOutputType::default(), &msg);
+                    return;
+                }
+            };
+
             // Invoke the default handler, which prints the actual panic message and optionally a backtrace
             (*DEFAULT_HOOK)(info);