-
-
Notifications
You must be signed in to change notification settings - Fork 746
fix: should not panic when SRI options is invalid #12259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for rspack canceled.
|
There was a problem hiding this 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 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.
📦 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
|
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 rspack-contrib/rspack-plugin-ci#12
Related links
Checklist