Skip to content

feat(regular_expression): improve error messages#16953

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-16-feat_regular_expression_improve_error_messages
Dec 19, 2025
Merged

feat(regular_expression): improve error messages#16953
graphite-app[bot] merged 1 commit intomainfrom
12-16-feat_regular_expression_improve_error_messages

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Dec 16, 2025

Improved error messages for regex parse failures.

Copy link
Member Author

sapphi-red commented Dec 16, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 16, 2025

CodSpeed Performance Report

Merging #16953 will not alter performance

Comparing 12-16-feat_regular_expression_improve_error_messages (6e13eda) with main (3c39d46)

Summary

✅ 42 untouched
⏩ 3 skipped1

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sapphi-red sapphi-red changed the base branch from 12-16-fix_regular_expression_correct_named_capture_group_reference_error to graphite-base/16953 December 16, 2025 11:29
@sapphi-red sapphi-red force-pushed the 12-16-feat_regular_expression_improve_error_messages branch from 29407b9 to c70e2c8 Compare December 16, 2025 11:38
@sapphi-red sapphi-red changed the base branch from graphite-base/16953 to 12-16-fix_regular_expression_correct_named_capture_group_reference_error December 16, 2025 11:38
@github-actions github-actions bot added the A-linter Area - Linter label Dec 16, 2025
@graphite-app graphite-app bot force-pushed the 12-16-fix_regular_expression_correct_named_capture_group_reference_error branch from 6d2d18c to b068bbf Compare December 16, 2025 11:39
@graphite-app graphite-app bot force-pushed the 12-16-feat_regular_expression_improve_error_messages branch 2 times, most recently from 51f0fa2 to 10bef7f Compare December 16, 2025 11:40
@sapphi-red sapphi-red force-pushed the 12-16-feat_regular_expression_improve_error_messages branch from 10bef7f to 6ba13c3 Compare December 16, 2025 12:09
@sapphi-red sapphi-red force-pushed the 12-16-fix_regular_expression_correct_named_capture_group_reference_error branch from b068bbf to bac65ed Compare December 16, 2025 12:09
@graphite-app graphite-app bot changed the base branch from 12-16-fix_regular_expression_correct_named_capture_group_reference_error to graphite-base/16953 December 17, 2025 00:38
@graphite-app graphite-app bot force-pushed the 12-16-feat_regular_expression_improve_error_messages branch from 6ba13c3 to 6642764 Compare December 17, 2025 00:46
@graphite-app graphite-app bot force-pushed the graphite-base/16953 branch from bac65ed to 5a2af88 Compare December 17, 2025 00:46
@graphite-app graphite-app bot changed the base branch from graphite-base/16953 to main December 17, 2025 00:46
@graphite-app graphite-app bot force-pushed the 12-16-feat_regular_expression_improve_error_messages branch from 6642764 to b6368a6 Compare December 17, 2025 00:47
@sapphi-red sapphi-red force-pushed the 12-16-feat_regular_expression_improve_error_messages branch 2 times, most recently from 2b94d9e to 9d8630a Compare December 17, 2025 07:39
@sapphi-red sapphi-red marked this pull request as ready for review December 17, 2025 07:48
Copilot AI review requested due to automatic review settings December 17, 2025 07:48
Copy link
Contributor

Copilot AI left a 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 enhances error messages for regular expression parsing failures by adding helpful, actionable guidance to diagnostic messages. The changes improve developer experience by providing specific suggestions for fixing regex errors, such as explaining valid flags, suggesting fixes for common mistakes, and showing available group names for invalid references.

Key changes:

  • Added help messages to all regex parser diagnostics with specific, actionable guidance
  • Enhanced reference error messages to show available groups/names
  • Improved error specificity by splitting generic errors into more targeted ones (e.g., duplicated vs invalid modifiers)

Reviewed changes

Copilot reviewed 7 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/oxc_regular_expression/src/diagnostics.rs Added help messages to all diagnostic functions with actionable guidance for fixing regex errors
crates/oxc_regular_expression/src/parser/pattern_parser/pattern_parser_impl.rs Updated to pass context (group counts, available names) to diagnostics for better error messages
crates/oxc_regular_expression/src/parser/flags_parser.rs Exported constants for valid flags and modifiers to use in help messages
crates/oxc_regular_expression/src/parser/mod.rs Re-exported flags/modifiers constants for use in diagnostics
crates/oxc_regular_expression/tests/diagnostics.rs Added test cases for new error scenarios with better context
Snapshot files Updated to reflect new help messages in diagnostic output

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@leaysgur leaysgur left a comment

Choose a reason for hiding this comment

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

Good work as always. 🕺🏻

I have 2 points:

  • Want to keep diagnostics() a pure function
    • Pass VALID_XXX as an argument only where necessary
  • Use VALID_XXX in the implementation as well
    • Some code changes might be needed, but I want to avoid double definitions

Does it make sense?

@sapphi-red
Copy link
Member Author

Would you elaborate what you mean by diagnostics()?

@leaysgur
Copy link
Member

leaysgur commented Dec 17, 2025

use xxx::VALID_FLAGS;

#[cold]
pub fn unknown_flag(span: Span, flag: &str) -> OxcDiagnostic {
    OxcDiagnostic::error(format!("{PREFIX} Unknown flag: `{flag}` found"))
        .with_label(span)
        .with_help(format!("Valid flags are: {}", VALID_FLAGS.join(", ")))
}

⬇️

#[cold]
pub fn unknown_flag(span: Span, flag: &str, valid_flags) -> OxcDiagnostic {
    OxcDiagnostic::error(format!("{PREFIX} Unknown flag: `{flag}` found"))
        .with_label(span)
        .with_help(format!("Valid flags are: {}", valid_flags.join(", ")))
}

However, this is nits. 😅

@sapphi-red
Copy link
Member Author

Ah, I see.

@sapphi-red sapphi-red force-pushed the 12-16-feat_regular_expression_improve_error_messages branch 2 times, most recently from ea162dd to 3804102 Compare December 17, 2025 09:10
@sapphi-red sapphi-red requested a review from leaysgur December 18, 2025 13:06
Copy link
Member

@leaysgur leaysgur left a comment

Choose a reason for hiding this comment

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

🙏🏻

@sapphi-red sapphi-red force-pushed the 12-16-feat_regular_expression_improve_error_messages branch from 3804102 to 6e13eda Compare December 19, 2025 02:00
@sapphi-red sapphi-red requested a review from leaysgur December 19, 2025 02:01
Copy link
Member

@leaysgur leaysgur left a comment

Choose a reason for hiding this comment

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

Thank you~! 🎅🏻

@leaysgur leaysgur added the 0-merge Merge with Graphite Merge Queue label Dec 19, 2025
Copy link
Member

leaysgur commented Dec 19, 2025

Merge activity

Improved error messages for regex parse failures.
@graphite-app graphite-app bot force-pushed the 12-16-feat_regular_expression_improve_error_messages branch from 6e13eda to 3e2ae7b Compare December 19, 2025 02:22
@leaysgur leaysgur removed the 0-merge Merge with Graphite Merge Queue label Dec 19, 2025
@leaysgur
Copy link
Member

I've just noticed that our release flow is now running.

I'll add the merge label again once the release has finished.

@leaysgur leaysgur added the 0-merge Merge with Graphite Merge Queue label Dec 19, 2025
@graphite-app graphite-app bot merged commit 3e2ae7b into main Dec 19, 2025
20 checks passed
@graphite-app graphite-app bot deleted the 12-16-feat_regular_expression_improve_error_messages branch December 19, 2025 03:26
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments