Skip to content

improve general error handling @renderToStream - #15213

Open
user93390 wants to merge 4 commits into
vuejs:mainfrom
user93390:main
Open

improve general error handling @renderToStream#15213
user93390 wants to merge 4 commits into
vuejs:mainfrom
user93390:main

Conversation

@user93390

@user93390 user93390 commented Aug 5, 2026

Copy link
Copy Markdown
  • improved error clarification in interface SimpleReadable
  • Improve error handling when destroy has error.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error reporting when streaming content to web writable destinations.
    • Stream failures now abort destinations cleanly without attempting to close them.
    • Prevented secondary rejection errors from obscuring the original rendering failure.
    • Updated stream-destruction notifications to use error-level console logging for clearer diagnostics.
    • Improved reliability when rendering fails during streamed output, including destinations that reject abort requests.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ffaa098-7062-416e-94a0-e11b3d270eb9

📥 Commits

Reviewing files that changed from the base of the PR and between ee49c1b and 2e0986e.

📒 Files selected for processing (1)
  • packages/server-renderer/__tests__/webStream.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/server-renderer/tests/webStream.spec.ts

📝 Walkthrough

Walkthrough

The stream renderer documents the destroy error parameter. Web Writable piping now logs destruction failures with console.error and aborts the writable while suppressing the abort rejection. Tests cover the updated behavior.

Changes

Stream error handling

Layer / File(s) Summary
Web Writable destruction handling
packages/server-renderer/src/renderToStream.ts
SimpleReadable.destroy names and documents its error parameter. pipeToWebWritable logs destruction failures with console.error and calls writer.abort, suppressing the resulting rejection.
Stream error test coverage
packages/server-renderer/__tests__/webStream.spec.ts
A shared populate helper replaces duplicated stream-reading logic. Tests verify the abort error, writer state, error logging, and suppression of rejected abort promises.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: improved error handling in renderToStream.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/server-renderer/src/renderToStream.ts (1)

211-215: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add regression coverage for the destruction path.

The existing packages/server-renderer/__tests__/webStream.spec.ts:41-66 test covers only successful output. Add a case that triggers destroy(err) and verifies that writer.abort(err) receives the same error, writer.close() is not called, and a rejected abort does not escape.

🤖 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 `@packages/server-renderer/src/renderToStream.ts` around lines 211 - 215, Add
regression coverage for the destroy(err) path in the web stream tests,
exercising the stream implementation around destroy and writer.abort. Verify the
original error is passed to writer.abort, writer.close is not called, and a
rejected abort is swallowed without escaping.
🤖 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 `@packages/server-renderer/src/renderToStream.ts`:
- Around line 18-22: Update the exported SimpleReadable.destroy method signature
to accept unknown instead of any, keeping its existing void return type and
behavior unchanged.

---

Nitpick comments:
In `@packages/server-renderer/src/renderToStream.ts`:
- Around line 211-215: Add regression coverage for the destroy(err) path in the
web stream tests, exercising the stream implementation around destroy and
writer.abort. Verify the original error is passed to writer.abort, writer.close
is not called, and a rejected abort is swallowed without escaping.
🪄 Autofix

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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 736cb460-d796-4a6a-b8cc-d86b5ecb1f76

📥 Commits

Reviewing files that changed from the base of the PR and between d2c458b and ab27482.

📒 Files selected for processing (1)
  • packages/server-renderer/src/renderToStream.ts

Comment on lines +18 to +22
/**
Call destroy when an error occurred
@param error - error that happened. Typed as unknown.
*/
destroy(error: any): void

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 4 '\bSimpleReadable\b|\bdestroy\s*\(' packages --glob '*.ts'

Repository: vuejs/core

Length of output: 10210


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '60,220p' packages/server-renderer/src/renderToStream.ts | nl -ba -v60

Repository: vuejs/core

Length of output: 188


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
p = Path("packages/server-renderer/src/renderToStream.ts")
lines = p.read_text(encoding="utf-8").splitlines()
for i in range(59, 220):
    print(f"{i+1}: {lines[i]}")
PY

Repository: vuejs/core

Length of output: 4822


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
p = Path("packages/server-renderer/src/renderToStream.ts")
lines = p.read_text(encoding="utf-8").splitlines()
for i in range(1, 60):
    print(f"{i:03d}: {lines[i-1]}")
PY

Repository: vuejs/core

Length of output: 1900


Align SimpleReadable.destroy with its documented type.

destroy is documented as receiving unknown, but the exported interface declares any, allowing callers to pass any destruction error without narrowing. Use unknown in the signature.

Proposed fix
-  destroy(error: any): void
+  destroy(error: unknown): void
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
Call destroy when an error occurred
@param error - error that happened. Typed as unknown.
*/
destroy(error: any): void
/**
Call destroy when an error occurred
`@param` error - error that happened. Typed as unknown.
*/
destroy(error: unknown): void
🤖 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 `@packages/server-renderer/src/renderToStream.ts` around lines 18 - 22, Update
the exported SimpleReadable.destroy method signature to accept unknown instead
of any, keeping its existing void return type and behavior unchanged.

update(webStream.spec.ts): Add regression coverage for the destruction path. (code rabbit)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/server-renderer/__tests__/webStream.spec.ts (1)

88-103: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the destruction diagnostic.

Both tests replace console.error but do not verify its call. toHaveBeenWarned() verifies the render warning. It does not verify the new pipeToWebWritable log. Assert that console.error receives the destruction message and the original render error.

Proposed fix
   expect(abortMock).toHaveBeenCalledWith(error)
+  expect(consoleErrorSpy).toHaveBeenCalledWith(
+    'Error while destroying stream: ',
+    error,
+  )
   expect(closeMock).not.toHaveBeenCalled()

Also applies to: 126-139

🤖 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 `@packages/server-renderer/__tests__/webStream.spec.ts` around lines 88 - 103,
Update the affected tests around pipeToWebWritable to assert consoleErrorSpy was
called with the destruction diagnostic message and the original render error,
while retaining the existing toHaveBeenWarned assertion for the render warning.
Apply the same assertion to both test cases that mock console.error.
🤖 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 `@packages/server-renderer/__tests__/webStream.spec.ts`:
- Around line 15-26: Update the populate function’s recursive reader.read flow
to decode each chunk with the TextDecoder streaming option enabled, preserving
incomplete UTF-8 sequences across chunk boundaries, and flush the decoder with a
final decode after done before returning res.

---

Nitpick comments:
In `@packages/server-renderer/__tests__/webStream.spec.ts`:
- Around line 88-103: Update the affected tests around pipeToWebWritable to
assert consoleErrorSpy was called with the destruction diagnostic message and
the original render error, while retaining the existing toHaveBeenWarned
assertion for the render warning. Apply the same assertion to both test cases
that mock console.error.
🪄 Autofix

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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 864c7675-f422-4b19-b497-da9fe660de3c

📥 Commits

Reviewing files that changed from the base of the PR and between ab27482 and ee49c1b.

📒 Files selected for processing (2)
  • packages/server-renderer/__tests__/webStream.spec.ts
  • packages/server-renderer/src/renderToStream.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/server-renderer/src/renderToStream.ts

Comment thread packages/server-renderer/__tests__/webStream.spec.ts
@edison1105 edison1105 added the 🧹 p1-chore Priority 1: this doesn't change code behavior. label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🧹 p1-chore Priority 1: this doesn't change code behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants