Skip to content

Conversation

@LingyuCoder
Copy link
Contributor

@LingyuCoder LingyuCoder commented Nov 21, 2025

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 the From trait. 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

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings November 21, 2025 06:15
@netlify
Copy link

netlify bot commented Nov 21, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 6b37f2b
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6920036c9934160008660c1e

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: bug fix release: bug related release(mr only) labels Nov 21, 2025
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 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 From to TryFrom for SubresourceIntegrityHashFunction and IntegrityHtmlPlugin, returning validation errors instead of panicking
  • Added deferred error reporting mechanism via validate_error field in the plugin, allowing invalid configurations to be reported as compilation errors
  • Added Default implementations 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.

@github-actions
Copy link
Contributor

📦 Binary Size-limit

Comparing 6b37f2b to feat: support SRI with experiments.css and CssExtractRspackPlugin (#12239) by harpsealjs

❌ Size increased by 3.63KB from 47.63MB to 47.63MB (⬆️0.01%)

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 21, 2025

CodSpeed Performance Report

Merging #12259 will not alter performance

Comparing fix/sri-options-panic (6b37f2b) with main (5322cc8)

Summary

✅ 17 untouched

@LingyuCoder LingyuCoder requested a review from hardfist November 21, 2025 08:42
@LingyuCoder LingyuCoder enabled auto-merge (squash) November 21, 2025 08:46
@LingyuCoder LingyuCoder merged commit 888337a into main Nov 21, 2025
58 checks passed
@LingyuCoder LingyuCoder deleted the fix/sri-options-panic branch November 21, 2025 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants