Skip to content

Commit 09b6e25

Browse files
committed
fix(cli): simplify panic hook setup and improve doc comments
Remove rolldown-specific assumptions from comments. The double take_hook pattern works regardless of whether rolldown's hook is present (local dev) or not (future rolldown changes). Add Once guard and remove extra trailing newline.
1 parent aa38de7 commit 09b6e25

File tree

1 file changed

+5
-7
lines changed
  • packages/cli/binding/src

1 file changed

+5
-7
lines changed

packages/cli/binding/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,19 @@ fn format_error_message(error: &(dyn StdError + 'static)) -> String {
123123
message
124124
}
125125

126-
/// Override rolldown's panic hook with a vite-plus specific one.
126+
/// Install a Vite+ panic hook so panics are correctly attributed to Vite+.
127127
///
128-
/// rolldown_binding sets a global panic hook in its `#[module_init]` that prints
129-
/// "Rolldown panicked" for ALL panics. Since vite-plus bundles rolldown into the
130-
/// same binary, we need to replace it so panics are correctly attributed to Vite+.
128+
/// Discards any previously set hook (e.g. rolldown's) via double `take_hook`:
129+
/// first call removes the current hook, second captures the restored default.
130+
/// Safe to call regardless of whether a custom hook was installed.
131131
#[allow(clippy::disallowed_macros)]
132132
fn setup_panic_hook() {
133133
static ONCE: std::sync::Once = std::sync::Once::new();
134134
ONCE.call_once(|| {
135-
// First take_hook discards rolldown's custom hook (which wraps the default
136-
// in a closure that prints "Rolldown panicked"). Second gets the real default.
137135
let _ = std::panic::take_hook();
138136
let default_hook = std::panic::take_hook();
139137
std::panic::set_hook(Box::new(move |info| {
140-
eprintln!("Vite+ panicked. This is a bug in Vite+, not your code.\n");
138+
eprintln!("Vite+ panicked. This is a bug in Vite+, not your code.");
141139
default_hook(info);
142140
eprintln!(
143141
"\nPlease report this issue at: https://github.com/voidzero-dev/vite-plus/issues/new?template=bug_report.yml"

0 commit comments

Comments
 (0)