Skip to content

Comments

fix: change filename template validation errors from UNHANDLEABLE_ERROR to INVALID_OPTION#7472

Merged
sapphi-red merged 7 commits intomainfrom
copilot/improve-validation-error-code
Dec 15, 2025
Merged

fix: change filename template validation errors from UNHANDLEABLE_ERROR to INVALID_OPTION#7472
sapphi-red merged 7 commits intomainfrom
copilot/improve-validation-error-code

Conversation

Copy link
Contributor

Copilot AI commented Dec 12, 2025

Two validation errors in filename_template.rs were incorrectly using UNHANDLEABLE_ERROR code instead of INVALID_OPTION. These errors occur when filename patterns contain absolute/relative paths or when [name] placeholders receive invalid path values.

Changes

Error type infrastructure:

  • Added InvalidFilenamePattern and InvalidFilenameSubstitution variants to InvalidOptionType enum
  • Created FilenameTemplateError type with corresponding variants
  • Updated FilenameTemplate::render() to validate patterns and return Result<String, FilenameTemplateError>
  • Both pattern validation and name substitution validation occur in render() method

Error conversion:

  • Modified downcast_napi_error_diagnostics() to unwrap BuildDiagnostic from anyhow::Error, preventing misclassification as UNHANDLEABLE_ERROR
  • Updated all call sites that invoke render() (chunk/mod.rs, file_emitter.rs, generate_stage/mod.rs) to convert FilenameTemplateError to BuildDiagnostic with proper error code

Before:

[UNHANDLEABLE_ERROR] Error: Something went wrong inside rolldown, please report this problem...
Invalid pattern "/absolute/[name].js" for "entryFileNames"...

After:

[INVALID_OPTION] Error: Invalid pattern "/absolute/[name].js" for "entryFileNames", 
patterns can be neither absolute nor relative paths...
Original prompt

Improve these two errors to have VALIDATION_ERROR error code instead of UNHANDLEABLE_ERROR

anyhow::bail!(
"Invalid pattern \"{}\" for \"{}\", patterns can be neither absolute nor relative paths. \
If you want your files to be stored in a subdirectory, write its name without a leading \
slash like this: subdirectory/pattern.",
self.template,
pattern_name
);
}
let mut tmp = self.template;
if let Some(name) = name {
// Validate the name replacement
if is_path_fragment(name) {
anyhow::bail!(
"Invalid substitution \"{name}\" for placeholder \"[name]\" in \"{pattern_name}\" pattern, \
can be neither absolute nor relative path."
);
}


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@netlify
Copy link

netlify bot commented Dec 12, 2025

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 01b66cb
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/693f65747496c10008e13665
😎 Deploy Preview https://deploy-preview-7472--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI and others added 2 commits December 12, 2025 03:17
…r code

- Add InvalidFilenamePattern and InvalidFilenameSubstitution to InvalidOptionType enum
- Create FilenameTemplateError type for specific validation errors
- Update FilenameTemplate::render() to return FilenameTemplateError instead of anyhow::Error
- Convert FilenameTemplateError to InvalidOption in file_emitter.rs and generate_stage/mod.rs
- Update error messages to maintain consistency with existing validation errors

Co-authored-by: sapphi-red <[email protected]>
…EABLE_ERROR

- Add validation to FilenameTemplate::new() to check for invalid patterns
- Update downcast_napi_error_diagnostics to properly unwrap BuildDiagnostic from anyhow::Error
- Convert FilenameTemplateError to BuildDiagnostic with INVALID_OPTION error code
- Update all callers to handle the new Result type from FilenameTemplate::new()
- Add test for invalid filename pattern that validates error code

Co-authored-by: sapphi-red <[email protected]>
Copilot AI changed the title [WIP] Update error codes to VALIDATION_ERROR Change filename template validation errors from UNHANDLEABLE_ERROR to INVALID_OPTION Dec 12, 2025
Copilot AI requested a review from sapphi-red December 12, 2025 03:42
…er()

Per review feedback, reverted FilenameTemplate::new() to its original form that doesn't return Result.
Validation now happens only in render() method. Updated all call sites to handle errors from render()
instead of new(), converting FilenameTemplateError to BuildDiagnostic with INVALID_OPTION error code.

Co-authored-by: sapphi-red <[email protected]>
@github-actions
Copy link
Contributor

github-actions bot commented Dec 12, 2025

Benchmarks Rust

  • target: main(90b2209)
  • pr: copilot/improve-validation-error-code(01b66cb)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     63.6±1.39ms        ? ?/sec    1.00     63.5±1.37ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.01     70.2±1.26ms        ? ?/sec    1.00     69.6±2.52ms        ? ?/sec
bundle/bundle@rome_ts                                        1.02    109.1±3.31ms        ? ?/sec    1.00    106.9±2.33ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.02    121.7±2.46ms        ? ?/sec    1.00    119.6±1.71ms        ? ?/sec
bundle/bundle@threejs                                        1.00     40.0±2.68ms        ? ?/sec    1.04     41.7±2.69ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.03     43.7±1.73ms        ? ?/sec    1.00     42.6±0.86ms        ? ?/sec
bundle/bundle@threejs10x                                     1.01    397.7±5.75ms        ? ?/sec    1.00    393.6±6.83ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.02    462.3±7.74ms        ? ?/sec    1.00    451.6±2.65ms        ? ?/sec
scan/scan@rome_ts                                            1.01     84.5±1.73ms        ? ?/sec    1.00     83.5±2.34ms        ? ?/sec
scan/scan@threejs                                            1.03     28.9±1.49ms        ? ?/sec    1.00     28.2±0.37ms        ? ?/sec
scan/scan@threejs10x                                         1.01    295.6±4.70ms        ? ?/sec    1.00    292.6±3.62ms        ? ?/sec

@sapphi-red sapphi-red changed the title Change filename template validation errors from UNHANDLEABLE_ERROR to INVALID_OPTION fix: change filename template validation errors from UNHANDLEABLE_ERROR to INVALID_OPTION Dec 12, 2025
@sapphi-red sapphi-red requested review from IWANABETHATGUY and removed request for sapphi-red December 12, 2025 05:21
@sapphi-red sapphi-red assigned sapphi-red and unassigned sapphi-red Dec 12, 2025
@sapphi-red sapphi-red marked this pull request as ready for review December 12, 2025 05:21
Copilot AI review requested due to automatic review settings December 12, 2025 05:21
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 fixes two validation errors in filename template handling that were incorrectly using UNHANDLEABLE_ERROR instead of INVALID_OPTION. The changes introduce new error variants, update the error handling infrastructure, and ensure proper error categorization for filename pattern validation issues.

Key changes:

  • Added InvalidFilenamePattern and InvalidFilenameSubstitution variants to InvalidOptionType enum with descriptive error messages
  • Modified FilenameTemplate::render() to return Result<String, BuildDiagnostic> instead of anyhow::Result<String> for better error specificity
  • Enhanced downcast_napi_error_diagnostics() to check for BuildDiagnostic directly before attempting NAPI error downcasting, preventing misclassification

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/rolldown_error/src/utils/downcast_napi_error_diagnostics.rs Adds early BuildDiagnostic check to prevent incorrect error classification as UNHANDLEABLE_ERROR
crates/rolldown_error/src/build_diagnostic/events/invalid_option.rs Adds two new error variants with user-friendly messages for filename pattern validation failures
crates/rolldown_common/src/inner_bundler_options/types/filename_template.rs Updates return type and error handling to use new BuildDiagnostic variants
crates/rolldown/tests/rolldown/errors/invalid_option/invalid_filename_pattern/main.js Adds test fixture for invalid filename pattern scenario
crates/rolldown/tests/rolldown/errors/invalid_option/invalid_filename_pattern/artifacts.snap Snapshot verification showing correct INVALID_OPTION error code
crates/rolldown/tests/rolldown/errors/invalid_option/invalid_filename_pattern/_config.json Test configuration using absolute path pattern to trigger validation error

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

Co-authored-by: Copilot <[email protected]>
Signed-off-by: 翠 <[email protected]>
@sapphi-red sapphi-red enabled auto-merge (squash) December 15, 2025 01:41
@sapphi-red sapphi-red merged commit 418a6fb into main Dec 15, 2025
27 checks passed
@sapphi-red sapphi-red deleted the copilot/improve-validation-error-code branch December 15, 2025 01:50
This was referenced Dec 17, 2025
shulaoda added a commit that referenced this pull request Dec 17, 2025
## [1.0.0-beta.55] - 2025-12-17

### 🚀 Features

- add validation errors for incompatible `inlineDynamicImports` options (#7539) by @Copilot
- rolldown_plugin_vite_reporter: truncate long importer lists in ineffective dynamic import warnings (#7528) by @Copilot
- export `memfs` from `rolldown/experimental` for browser builds (#7490) by @Copilot
- implement `postBanner` and `postFooter` (#7487) by @sevenc-nanashi
- port getLogFilter helper from Rollup for advanced log filtering (#6890) by @taearls
- dev: initialize `rolldown_plugin_lazy_compilation` (#7488) by @hyf0
- enable `experimental.transform_hires_sourcemap: 'boundary'` by default (#7478) by @sapphi-red
- apply merge CJS namespace optimizations more generally (#7475) by @sapphi-red

### 🐛 Bug Fixes

- avoid panic on invalid values for `output.exports`, `output.format`, `output.hash_characters` (#7542) by @sapphi-red
- handle `__proto__` export for module namespace correctly (#7534) by @sapphi-red
- handle `__proto__` export correctly (#7533) by @sapphi-red
- rolldown_plugin_vite_resolve: acquire resolver lock before package json resolution (#7524) by @sapphi-red
- disable syntax transform optimization for `minify: 'dce-only'` (#7520) by @sapphi-red
- arrow function expression keep names (#7519) by @IWANABETHATGUY
- skip symbols that are imported from other module when deconflicting module symbols (#7510) by @IWANABETHATGUY
- preserve class names in assignment expressions with keepNames option (#7491) by @IWANABETHATGUY
- accessor with decorators should be kept (#7499) by @Copilot
- rolldown_plugin_vite_reporter: support `Infinity` for chunk_limit (#7497) by @shulaoda
- change filename template validation errors from UNHANDLEABLE_ERROR to INVALID_OPTION (#7472) by @Copilot
- `no entry found for key` error when merging CJS namespace exports (#7474) by @sapphi-red
- generate output with syntax error when wrapped esm module using tla syntax (#7468) by @IWANABETHATGUY

### 🚜 Refactor

- dev: rename `experimental.hmr` to `experimental.devMode` (#7527) by @hyf0
- pass addon option to rust as it is (#7526) by @hyf0
- remove unused stmtinfo meta flag (#7518) by @IWANABETHATGUY

### 📚 Documentation

- clarify `closeBundle` behavior (#7525) by @sapphi-red

### 🧪 Testing

- add tests for static string postBanner and postFooter (#7516) by @Copilot
- disable pluginTimings in Rust integration tests to avoid snapshot noise (#7485) by @shulaoda
- port Rollup JSX tests to `crates/rolldown/tests/rollup` (#7480) by @sapphi-red
- re-triage some esbuild JSX preserve tests (#7479) by @sapphi-red
- disable pluginTimings by default to avoid snapshot noise (#7471) by @shulaoda

### ⚙️ Miscellaneous Tasks

- mark feature that will not be supported as ignored in rollup test status (#7535) by @sapphi-red
- support `banner`/`footer`/`intro`/`outro` for config variants (#7532) by @sapphi-red
- `dce/dce_of_decorators` esbuild test is now passing (#7531) by @sapphi-red
- deps: update github-actions (major) (#7495) by @renovate[bot]
- deps: update npm packages (#7493) by @renovate[bot]
- add a check to verify failedReasons are updated (#7521) by @sapphi-red
- deps: update test262 submodule for tests (#7523) by @sapphi-red
- deps: update taiki-e/install-action action to v2.63.2 (#7496) by @renovate[bot]
- deps: update oxc apps (#7511) by @renovate[bot]
- deps: update oxc to v0.103.0 (#7513) by @camc314
- fix format in `.github/instructions/bug-investigation.instructions.md` (#7506) by @sapphi-red
- add instructions for REPL decoding (#7502) by @sapphi-red
- deps: update github-actions (#7492) by @renovate[bot]
- deps: cargo-shear v1.9.0 (#7483) by @Boshen
- deps: update dependency oxlint-tsgolint to v0.9.0 (#7484) by @renovate[bot]
- deps: update dependency oxlint-tsgolint to v0.8.6 (#7470) by @renovate[bot]
- add syntax validation for test output chunks that are not executed (#7466) by @IWANABETHATGUY
- deps: update dependency rust to v1.92.0 (#7467) by @renovate[bot]
- deps: update test262 submodule for tests (#7457) by @sapphi-red

### ❤️ New Contributors

* @sevenc-nanashi made their first contribution in [#7487](#7487)
* @taearls made their first contribution in [#6890](#6890)

Co-authored-by: shulaoda <[email protected]>
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.

3 participants