Missing error handling in Share API fetch calls leads to silent failures #8268

Open
opened 2026-02-16 18:09:33 -05:00 by yindo · 1 comment
Owner

Originally created by @riftzen-bit on GitHub (Feb 1, 2026).

Originally assigned to: @rekram1-node on GitHub.

Summary

The Share module's fetch calls lack proper error handling, which can cause unhandled promise rejections and silent failures.

Location

packages/opencode/src/share/share.ts:29-46, 77-82, 87-90

Issue

1. sync() function (line 29) - No error handling

return fetch(\`\${URL}/share_sync\`, {
  method: "POST",
  body: JSON.stringify({...}),
})
// Missing .catch() - network errors cause unhandled rejection

2. create() function (lines 77-82) - No HTTP status check

return fetch(\`\${URL}/share_create\`, {...})
  .then((x) => x.json())  // No check for response.ok
  .then((x) => x as { url: string; secret: string })

3. remove() function (lines 87-90) - Same issues

Impact

  • Severity: Medium
  • Share sync failures are never logged or reported
  • HTTP errors (4xx, 5xx) are treated as success
  • Network failures cause unhandled promise rejections

Suggested Fix

Add proper error handling with status checks:

export async function create(sessionID: string) {
  if (disabled) return { url: "", secret: "" }
  const response = await fetch(\`\${URL}/share_create\`, {
    method: "POST",
    body: JSON.stringify({ sessionID }),
  })
  if (!response.ok) {
    throw new Error(\`HTTP \${response.status}\`)
  }
  return await response.json() as { url: string; secret: string }
}
Originally created by @riftzen-bit on GitHub (Feb 1, 2026). Originally assigned to: @rekram1-node on GitHub. ## Summary The Share module's fetch calls lack proper error handling, which can cause unhandled promise rejections and silent failures. ## Location `packages/opencode/src/share/share.ts:29-46, 77-82, 87-90` ## Issue ### 1. sync() function (line 29) - No error handling ```typescript return fetch(\`\${URL}/share_sync\`, { method: "POST", body: JSON.stringify({...}), }) // Missing .catch() - network errors cause unhandled rejection ``` ### 2. create() function (lines 77-82) - No HTTP status check ```typescript return fetch(\`\${URL}/share_create\`, {...}) .then((x) => x.json()) // No check for response.ok .then((x) => x as { url: string; secret: string }) ``` ### 3. remove() function (lines 87-90) - Same issues ## Impact - **Severity**: Medium - Share sync failures are never logged or reported - HTTP errors (4xx, 5xx) are treated as success - Network failures cause unhandled promise rejections ## Suggested Fix Add proper error handling with status checks: ```typescript export async function create(sessionID: string) { if (disabled) return { url: "", secret: "" } const response = await fetch(\`\${URL}/share_create\`, { method: "POST", body: JSON.stringify({ sessionID }), }) if (!response.ok) { throw new Error(\`HTTP \${response.status}\`) } return await response.json() as { url: string; secret: string } } ```
Author
Owner

@github-actions[bot] commented on GitHub (Feb 1, 2026):

This issue is part of a broader error handling improvement initiative. While not exact duplicates, it's related to similar error handling patterns being addressed in:

  • #11698: Unprotected JSON.parse in provider fetch wrapper can crash requests
  • #11701: Empty catch blocks silently swallow errors in config and initialization
  • #11700: Missing array bounds checking in LLM provider response handling

Additionally, there are existing Share session issues that may be related to error handling gaps:

  • #8110: [Share Session] Error | Uncaught Client Exception
  • #6981: Error | Uncaught Client Exception on Share page

Feel free to coordinate with these related issues when implementing error handling improvements.

@github-actions[bot] commented on GitHub (Feb 1, 2026): This issue is part of a broader error handling improvement initiative. While not exact duplicates, it's related to similar error handling patterns being addressed in: - #11698: Unprotected JSON.parse in provider fetch wrapper can crash requests - #11701: Empty catch blocks silently swallow errors in config and initialization - #11700: Missing array bounds checking in LLM provider response handling Additionally, there are existing Share session issues that may be related to error handling gaps: - #8110: [Share Session] Error | Uncaught Client Exception - #6981: Error | Uncaught Client Exception on Share page Feel free to coordinate with these related issues when implementing error handling improvements.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8268