Skip to content

Commit c81be2e

Browse files
authored
fix(es): Don't panic when wasm bytecheck faild (#9803)
**Description:** Currently when wasm plugin is not compatible with swc version it will panic which cause it hard to report useful error info from caller except use catch_unwind. change the behavior to not panic and let the user to decide error handling
1 parent 9eceec4 commit c81be2e

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

Diff for: .changeset/new-apricots-exercise.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc: patch
3+
swc_core: patch
4+
---
5+
6+
fix: don't panic when wasm bytecheck faild

Diff for: crates/swc/src/plugin.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
)]
88

99
use serde::{Deserialize, Serialize};
10+
use swc_common::errors::HANDLER;
1011
use swc_ecma_ast::Pass;
1112
#[cfg(feature = "plugin")]
1213
use swc_ecma_ast::*;
@@ -165,15 +166,27 @@ impl Fold for RustPlugins {
165166

166167
#[cfg(feature = "plugin")]
167168
fn fold_module(&mut self, n: Module) -> Module {
168-
self.apply(Program::Module(n))
169-
.expect("failed to invoke plugin")
170-
.expect_module()
169+
match self.apply(Program::Module(n)) {
170+
Ok(program) => program.expect_module(),
171+
Err(err) => {
172+
HANDLER.with(|handler| {
173+
handler.err(&err.to_string());
174+
});
175+
Module::default()
176+
}
177+
}
171178
}
172179

173180
#[cfg(feature = "plugin")]
174181
fn fold_script(&mut self, n: Script) -> Script {
175-
self.apply(Program::Script(n))
176-
.expect("failed to invoke plugin")
177-
.expect_script()
182+
match self.apply(Program::Script(n)) {
183+
Ok(program) => program.expect_script(),
184+
Err(err) => {
185+
HANDLER.with(|handler| {
186+
handler.err(&err.to_string());
187+
});
188+
Script::default()
189+
}
190+
}
178191
}
179192
}

0 commit comments

Comments
 (0)