Refactor: Improve WorkerError Handling and Stack Trace Merging for Thread Loader#246
Refactor: Improve WorkerError Handling and Stack Trace Merging for Thread Loader#246Manas-Dikshit wants to merge 10 commits intowebpack:mainfrom
Conversation
alexander-akait
left a comment
There was a problem hiding this comment.
Please add a test case
|
Thanks for pointing that out, Alexander – I’ve added a specific test case for the new WorkerError behavior. |
alexander-akait
left a comment
There was a problem hiding this comment.
Please add integration test, not unit tests, they are useles
|
Please use our test infrastructure, not own |
alexander-akait
left a comment
There was a problem hiding this comment.
Please use EXISTING infrastructure - https://github.com/webpack/thread-loader/blob/main/test/webpack.test.js
test: use existing webpack test infra for worker-error integration test
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
ci: ignore merge commits in commitlint; test: add WorkerError unit tests
This pull request refactors the WorkerError implementation to make it more reliable and easier to read.
The new version handles edge cases more safely, avoids runtime errors, and produces clearer stack traces for worker threads.
What Changed
Replaced the old stack() helper with a safer buildStackTrace() utility
Added default values for missing properties (err, err.stack, workerId)
Improved how stack trace differences are calculated and merged
Cleaned up variable names and improved code readability
Ensured consistent formatting across all generated error messages
Why This Matters
The previous version could throw additional errors if err or its stack were missing.
With these improvements, developers get cleaner output and more reliable debugging information when using thread-based loaders.
Example Output
Thread Loader (Worker 3)
ReferenceError: x is not defined
at doSomething (worker.js:25:11)
at Worker.run (thread.js:10:5)
Next Steps
Consider adding a toJSON() method to support structured logging or error reporting across worker boundaries.