[PR #5] [CLOSED] Fix unreachable case "error" branches by making streamEvents yield errors instead of throwing #4384

Closed
opened 2026-10-22 04:07:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5
Author: @Copilot
Created: 3/9/2026
Status: ❌ Closed

Base: release/1.2.0 ← Head: copilot/sub-pr-1-yet-again


📝 Commits (2)

  • 423f262 Initial plan
  • c745a0a Fix unreachable case "error" branches: change streamEvents to yield errors

📊 Changes

2 files changed (+17 additions, -13 deletions)

View changed files

📝 packages/client/src/hooks/use-generate.ts (+15 -8)
📝 packages/client/src/lib/api-client.ts (+2 -5)

📄 Description

api.streamEvents() was throwing an ApiError on { type: "error" } SSE events, making the case "error" switch branches in use-generate.ts dead code. Error handling was inconsistent: error events were exceptions while all other events were yielded.

Changes

api-client.ts

  • streamEvents now yields { type: "error", data } like any other event, then returns — making it a terminal event rather than a thrown exception
// Before
if (parsed.type === "error") {
  throw new ApiError(500, parsed.data ?? "Generation error");
}
yield parsed;

// After
yield parsed;
if (parsed.type === "error") return; // terminal event — stop iteration

use-generate.ts

  • Extracted flushTypewriterBuffer() helper to eliminate duplicated flush logic across case "error" and the catch block
  • case "error" in generate loop now reachable: calls flushTypewriterBuffer() + toast.error()
  • case "error" in retryAgents loop sets hasError = true to suppress the toast.success("Agent retry completed") that would otherwise fire after an error-terminated stream
  • catch blocks remain as fallback for unexpected errors (network failures, AbortError)

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 3/9/2026 **Status:** ❌ Closed **Base:** `release/1.2.0` ← **Head:** `copilot/sub-pr-1-yet-again` --- ### 📝 Commits (2) - [`423f262`](https://github.com/Pasta-Devs/Marinara-Engine/commit/423f262357b20bccf5fe8aa6215ecc5f6e5bdc08) Initial plan - [`c745a0a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c745a0a4213db319db94637e8fa53882c6219b9c) Fix unreachable case \"error\" branches: change streamEvents to yield errors ### 📊 Changes **2 files changed** (+17 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/hooks/use-generate.ts` (+15 -8) 📝 `packages/client/src/lib/api-client.ts` (+2 -5) </details> ### 📄 Description `api.streamEvents()` was throwing an `ApiError` on `{ type: "error" }` SSE events, making the `case "error"` switch branches in `use-generate.ts` dead code. Error handling was inconsistent: error events were exceptions while all other events were yielded. ## Changes ### `api-client.ts` - `streamEvents` now yields `{ type: "error", data }` like any other event, then `return`s — making it a terminal event rather than a thrown exception ```ts // Before if (parsed.type === "error") { throw new ApiError(500, parsed.data ?? "Generation error"); } yield parsed; // After yield parsed; if (parsed.type === "error") return; // terminal event — stop iteration ``` ### `use-generate.ts` - Extracted `flushTypewriterBuffer()` helper to eliminate duplicated flush logic across `case "error"` and the `catch` block - `case "error"` in `generate` loop now reachable: calls `flushTypewriterBuffer()` + `toast.error()` - `case "error"` in `retryAgents` loop sets `hasError = true` to suppress the `toast.success("Agent retry completed")` that would otherwise fire after an error-terminated stream - `catch` blocks remain as fallback for unexpected errors (network failures, `AbortError`) <!-- START COPILOT CODING AGENT TIPS --> --- 🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. [Learn more about Advanced Security.](https://gh.io/cca-advanced-security) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:07:07 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4384
No description provided.