-
-
Notifications
You must be signed in to change notification settings - Fork 749
fix: rspack error communicate between js and rust #10595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for rspack canceled.
|
CodSpeed Performance ReportMerging #10595 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors error handling to preserve messages and differentiate error types between JavaScript and Rust, cleans up obsolete hideStack behavior and tests, and updates Node binding modules to marshal errors and modules consistently.
- Remove legacy hideStack tests that no longer align with current error handling.
- Extend
Diagnostic
and introduceRspackError
to carrymessage
/details
and map names to Rust error types. - Update Node-binding code (
scheduler
,context
,module
,error
,compilation
) for accurate marshalling of errors and modules.
Reviewed Changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
packages/rspack-test-tools/tests/diagnosticsCases/module-build-failed/loader-emit-hide-stack/my-loader.js | Removed outdated loader hideStack test |
packages/rspack-test-tools/tests/configCases/errors/hide-stack/** | Removed obsolete hideStack config tests |
crates/rspack_error/src/diagnostic.rs | Added message /details fields and accessors to Diagnostic |
crates/rspack_core/src/normal_module.rs | Switched to ModuleBuildError::new(...) constructor usage |
crates/rspack_core/src/diagnostics.rs | Wrapped ModuleBuildError in a new struct with new method |
crates/node_binding/src/plugins/js_loader/scheduler.rs | Improved JS→Rust error message selection logic |
crates/node_binding/src/plugins/js_loader/context.rs | Renamed JS error type to RspackError |
crates/node_binding/src/module.rs | Adjusted ModuleObject sync/ownership handling |
crates/node_binding/src/location.rs | Derived Clone and added bidirectional conversions for types |
crates/node_binding/src/error.rs | Introduced RspackError for JS-Rust diagnostic marshalling |
crates/node_binding/src/compilation/mod.rs | Swapped JsRspackError for RspackError in compilation APIs |
crates/node_binding/src/compilation/diagnostics.rs | Updated diagnostics APIs to return RspackError |
Comments suppressed due to low confidence (5)
crates/node_binding/src/plugins/js_loader/scheduler.rs:88
- [nitpick] Comments are written in Chinese; consider translating them to English to maintain consistency with the rest of the codebase.
// 将 JS 传来的 Error message 转换为 Rust 需要的格式
crates/rspack_error/src/diagnostic.rs:172
- [nitpick] The
message()
method strips the "Name: " prefix by string manipulation. It may be more robust to use miette APIs that separate error code and message, avoiding manual string hacks.
pub fn message(&self) -> String {
packages/rspack-test-tools/tests/configCases/errors/hide-stack/index.js:1
- Removing these hide-stack tests reduces coverage for stack handling in
StatsError
andStatsWarning
. Ensure you add or update tests to cover the new error formatting behavior.
-it("should hide stack in details when throw", function () {
crates/node_binding/src/module.rs:474
- Implementing Sync for ModuleObject with an internal raw pointer may introduce race conditions if the underlying
Module
isn't thread-safe. Please verify that accesses tomodule
across threads are properly synchronized or consider using a thread-safe wrapper.
unsafe impl Sync for ModuleObject {}
crates/node_binding/src/module.rs:616
- Removing the
.take()
call changes ownership semantics of the raw module pointer, potentially leading to dangling pointers or memory leaks. Confirm the pointer’s lifetime remains valid and that no double-free scenarios are introduced.
module: normal_module.module.module,
Summary
This PR resolves an issue where reassigning compilation.errors[0] caused error messages to degrade to unhelpful [object Object] output:
Error message became corrupted:
After this PR error message is preserved.
Rust RspackError should accept JavaScript Error objects and reads these properties:
When converting RspackError to Diagnostic, RspackError now maps name to specific Rust error types (e.g., ModuleBuildError for clearer categorization.
This PR modify the following test cases as they no longer align with current error handling behavior:
The hideStack property has no effect on RspackError objects. This test case might have been intended to verify hideStack behavior for StatsError and StatsWarning instead.
Checklist