fix: should not panic when SRI options is invalid#12259
Merged
LingyuCoder merged 1 commit intomainfrom Nov 21, 2025
Merged
Conversation
✅ Deploy Preview for rspack canceled.
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR converts the SubresourceIntegrityPlugin's configuration validation from panicking From trait implementations to fallible TryFrom implementations, enabling graceful error handling through the compilation diagnostic system rather than runtime panics.
Key Changes:
- Converted
FromtoTryFromforSubresourceIntegrityHashFunctionandIntegrityHtmlPlugin, returning validation errors instead of panicking - Added deferred error reporting mechanism via
validate_errorfield in the plugin, allowing invalid configurations to be reported as compilation errors - Added
Defaultimplementations to support creating placeholder plugin instances when validation fails
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
crates/rspack_plugin_sri/src/integrity.rs |
Changed From to TryFrom for SubresourceIntegrityHashFunction, returning error for invalid hash function names instead of panicking |
crates/rspack_plugin_sri/src/config.rs |
Changed From to TryFrom for IntegrityHtmlPlugin and added Default derives for both enum and options struct to support error-case fallback |
crates/rspack_binding_api/src/raw_options/raw_builtins/raw_sri.rs |
Updated conversion to use TryFrom, added validation for empty hash functions list, and properly propagated conversion errors |
crates/rspack_plugin_sri/src/lib.rs |
Added validate_error field to plugin struct and corresponding error-reporting hook that executes when validation fails, preventing normal plugin execution |
crates/rspack_binding_api/src/raw_options/raw_builtins/mod.rs |
Modified plugin instantiation to handle validation errors by creating placeholder instances with stored errors instead of failing immediately |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📦 Binary Size-limit
❌ Size increased by 3.63KB from 47.63MB to 47.63MB (⬆️0.01%) |
CodSpeed Performance ReportMerging #12259 will not alter performanceComparing Summary
|
hardfist
approved these changes
Nov 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The zod is removed, so the validation will be processed by the rust plugin. Currently, most configurations are type-checked through
napi. After passing the check, an attempt is made to perform data conversion through theFromtrait. At this point, if the conversion fails, it will cause a panic.The behavior of the SRI plugin is to add an error to the compilation diagnostics when the validation fails. Therefore, the validation method needs to be modified so that a validation failure no longer causes a panic.
The test cases is in rstackjs/rspack-plugin-ci#12
Related links
Checklist