Skip to content

Refactor: Improve WorkerError Handling and Stack Trace Merging for Thread Loader#246

Open
Manas-Dikshit wants to merge 5 commits intowebpack:mainfrom
Manas-Dikshit:main
Open

Refactor: Improve WorkerError Handling and Stack Trace Merging for Thread Loader#246
Manas-Dikshit wants to merge 5 commits intowebpack:mainfrom
Manas-Dikshit:main

Conversation

@Manas-Dikshit
Copy link

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.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 25, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test case

@Manas-Dikshit
Copy link
Author

Thanks for pointing that out, Alexander – I’ve added a specific test case for the new WorkerError behavior.
It includes tests for correct stack merging, message handling, and default fallbacks when err or workerId are absent.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add integration test, not unit tests, they are useles

@alexander-akait
Copy link
Member

Please use our test infrastructure, not own

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants