Commit 658fd54
fix: don't use eprintln! in the panic hook (#13637)
### Problem
`panic_handler` ends with `eprintln!`, which **panics if the write to
stderr fails**. A panic raised inside a panic hook aborts the process
immediately, so the hook never completes and the crash report it exists
to print is lost. The user sees a bare `Aborted (core dumped)` with no
diagnostics at all.
This is reachable in practice during TUI teardown, where the terminal fd
can already be gone. Observed on 2.10.1 with a locally symbolized build:
```
turborepo_ui::tui::app::cleanup crates/turborepo-ui/src/tui/app.rs:1111
-> ratatui Terminal::drop ratatui-core/src/terminal/terminal.rs:119
eprintln!("Failed to show the cursor") -> write fails -> panic
-> turborepo_lib::panic_handler crates/turborepo-lib/src/panic_handler.rs:66
eprintln! -> write fails -> panic
-> double panic -> abort() (SIGABRT)
```
ratatui's `Drop` reports a failed `show_cursor` via `eprintln!`; that
write fails too and panics; the hook then panics the same way, and the
second panic aborts. The first panic is ratatui's to own — but the hook
shouldn't be capable of turning *any* panic into an abort.
### Fix
Write to stderr directly and discard the error:
```rust
let _ = std::io::stderr().write_all(
format!("Oops! Turbo has crashed.\n\n{report_message}\n").as_bytes(),
);
```
A panic hook runs precisely when things are already broken, so it
shouldn't assume its own output path works. If stderr is unusable we now
print nothing, instead of escalating to an abort. When stderr *is*
usable — the overwhelmingly common case — behaviour is unchanged.
### Notes / testing
- Applies to `main`; `eprintln!` is the only panicking macro in the
hook.
- The equivalent change was built and exercised on 2.10.1 (Linux, musl
target): the double-panic abort stopped reproducing.
- The changed code compiles standalone under `-D warnings` (no unused
import, no type error).
- **I have not built the full workspace against `main`** — I don't have
`capnp`/`zig` and the pinned nightly on this machine. Happy for CI to be
the judge, which is why this is a draft.
Filed as a draft for maintainer review; glad to adjust the wording or
add a regression test if useful.
---------
Co-authored-by: Anthony Shew <anthonyshew@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent a936402 commit 658fd54
1 file changed
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
0 commit comments