Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: DefinePlugin error reporting and evaluation safety#20260

Open
AarishMansur wants to merge 5 commits intowebpack:mainfrom
AarishMansur:feat/better-define-plugin-errors
Open

feat: DefinePlugin error reporting and evaluation safety#20260
AarishMansur wants to merge 5 commits intowebpack:mainfrom
AarishMansur:feat/better-define-plugin-errors

Conversation

@AarishMansur
Copy link

What is the expected behavior?

Errors that occur while evaluating values inside DefinePlugin should be reported clearly during compilation, with enough context to identify the failing definition.

What is the motivation or use case for adding/changing the behavior?

When DefinePlugin is misconfigured (for example, passing a raw string instead of a stringified value), the resulting errors are often vague or only appear at runtime. This makes debugging difficult and hurts DX.

How should this be implemented in your opinion?

Catch evaluation errors inside DefinePlugin and surface them as informative WebpackErrors, while ensuring internal recursion flags are always reset.

What does this PR do?

  • Wraps parser.evaluate() calls in try/catch/finally blocks
  • Replaces generic failures with clear WebpackError messages that include the failing key
  • Preserves the original error via error.cause for better stack traces
  • Ensures recursion flags are safely reset even when evaluation fails
  • Helps catch invalid define values earlier during compilation

Benefits

  • Better DX with clear, actionable error messages
  • Fail-fast behavior during build instead of runtime
  • Improved stability by avoiding stuck recursive states

Screenshot

repo pr

Are you willing to work on this yourself?

Yes.

@changeset-bot
Copy link

changeset-bot bot commented Dec 21, 2025

⚠️ No Changeset found

Latest commit: 1418b22

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 21, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@AarishMansur AarishMansur changed the title Improve DefinePlugin error reporting and evaluation safety feat: DefinePlugin error reporting and evaluation safety Dec 21, 2025
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 test cases in test/statsCases, thanks

@AarishMansur
Copy link
Author

@alexander-akait done lemme know if further changes are needed as well
Thanks !!

@alexander-akait
Copy link
Member

@AarishMansur please fix rebase, thanks

@AarishMansur AarishMansur force-pushed the feat/better-define-plugin-errors branch from d5aa9e2 to 27b7ae2 Compare December 23, 2025 14:26
@AarishMansur
Copy link
Author

@AarishMansur please fix rebase, thanks

@alexander-akait fixed rebased

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 25, 2025

CodSpeed Performance Report

Merging #20260 will not alter performance

Comparing AarishMansur:feat/better-define-plugin-errors (8128f14) with main (f21d135)

Summary

✅ 72 untouched

@AarishMansur
Copy link
Author

Hey @alexander-akait just checking if my PR needs further changes or not ?

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