fix(html-validate): wrap validation in a try/catch - #377
Conversation
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe Nitro Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/runtime/html-validate/nitro.plugin.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/runtime/html-validate/nitro.plugin.ts`:
- Around line 47-48: Separate Prettier formatting from validation in the handler
around formattedBody and validator.validateString: if format fails, fall back to
the original response.body, validate that string, and assign the same fallback
string to HtmlValidateReport.html. Preserve the existing reporting and
hook-event flow, and add a regression test covering the <foreignObject><picture>
case.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ffbf050e-4139-40de-a37e-ab381230bc2e
📒 Files selected for processing (1)
src/runtime/html-validate/nitro.plugin.ts
| const formattedBody = await format(response.body, { plugins: [html], parser: 'html' }) | ||
| const results = await validator.validateString(formattedBody) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Continue validation when formatting fails.
format and validator.validateString share one try block. If Prettier throws at Line [47], validation never processes the original HTML. The response avoids the HTTP 500, but it also loses the inline hints-html-validate report and the hints:html-validate:report hook event.
Catch the formatting error separately, validate response.body as the fallback, and set HtmlValidateReport.html to the same string. Add a regression test for the <foreignObject><picture> case.
Proposed fix
try {
- const formattedBody = await format(response.body, { plugins: [html], parser: 'html' })
- const results = await validator.validateString(formattedBody)
+ let htmlToValidate = response.body
+ try {
+ htmlToValidate = await format(response.body, { plugins: [html], parser: 'html' })
+ }
+ catch (error) {
+ console.warn('HTML formatting error:', error instanceof Error ? error.message : String(error))
+ }
+ const results = await validator.validateString(htmlToValidate)
...
- html: formattedBody,
+ html: htmlToValidate,Also applies to: 66-69
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/runtime/html-validate/nitro.plugin.ts` around lines 47 - 48, Separate
Prettier formatting from validation in the handler around formattedBody and
validator.validateString: if format fails, fall back to the original
response.body, validate that string, and assign the same fallback string to
HtmlValidateReport.html. Preserve the existing reporting and hook-event flow,
and add a regression test covering the <foreignObject><picture> case.
🔗 Linked issue
fix #360
📚 Description
wraps the validation in a try/catch statement. html-validate can throw with unexpected tags