Empty catch blocks silently swallow errors in config and initialization #8273

Open
opened 2026-02-16 18:09:34 -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

Several empty catch blocks in the codebase silently swallow errors, making debugging difficult and hiding potential issues from users.

Locations

  1. packages/opencode/src/config/config.ts:1235 - Plugin resolution errors swallowed
  2. packages/opencode/src/global/index.ts:53 - Initialization errors swallowed
  3. Multiple locations in file operations

Issue

1. Config plugin resolution (config.ts:1235)

for (let i = 0; i < data.plugin.length; i++) {
  const plugin = data.plugin[i]
  try {
    data.plugin[i] = import.meta.resolve!(plugin, configFilepath)
  } catch (err) {}  // Error completely swallowed - user has no idea plugin failed
}

2. Global initialization (global/index.ts:53)

try {
  const contents = await fs.readdir(Global.Path.cache)
  await Promise.all(
    contents.map((item) => fs.rm(path.join(Global.Path.cache, item), {...})),
  )
} catch (e) {}  // Cache cleanup failure hidden

Impact

  • Severity: Low-Medium
  • Type: Error Handling / Debugging
  • Effect:
    • Invalid plugins silently ignored, user sees no feedback
    • Initialization issues hidden
    • Makes troubleshooting difficult

Suggested Fix

Replace empty catch blocks with proper logging:

// config.ts
try {
  data.plugin[i] = import.meta.resolve!(plugin, configFilepath)
} catch (err) {
  log.warn("failed to resolve plugin", { plugin, error: err })
  // Optionally remove the invalid plugin from the array
}

// global/index.ts
try {
  // ...cache cleanup
} catch (e) {
  log.warn("failed to clear cache", { error: e })
}
Originally created by @riftzen-bit on GitHub (Feb 1, 2026). Originally assigned to: @rekram1-node on GitHub. ## Summary Several empty catch blocks in the codebase silently swallow errors, making debugging difficult and hiding potential issues from users. ## Locations 1. `packages/opencode/src/config/config.ts:1235` - Plugin resolution errors swallowed 2. `packages/opencode/src/global/index.ts:53` - Initialization errors swallowed 3. Multiple locations in file operations ## Issue ### 1. Config plugin resolution (config.ts:1235) ```typescript for (let i = 0; i < data.plugin.length; i++) { const plugin = data.plugin[i] try { data.plugin[i] = import.meta.resolve!(plugin, configFilepath) } catch (err) {} // Error completely swallowed - user has no idea plugin failed } ``` ### 2. Global initialization (global/index.ts:53) ```typescript try { const contents = await fs.readdir(Global.Path.cache) await Promise.all( contents.map((item) => fs.rm(path.join(Global.Path.cache, item), {...})), ) } catch (e) {} // Cache cleanup failure hidden ``` ## Impact - **Severity**: Low-Medium - **Type**: Error Handling / Debugging - **Effect**: - Invalid plugins silently ignored, user sees no feedback - Initialization issues hidden - Makes troubleshooting difficult ## Suggested Fix Replace empty catch blocks with proper logging: ```typescript // config.ts try { data.plugin[i] = import.meta.resolve!(plugin, configFilepath) } catch (err) { log.warn("failed to resolve plugin", { plugin, error: err }) // Optionally remove the invalid plugin from the array } // global/index.ts try { // ...cache cleanup } catch (e) { log.warn("failed to clear cache", { error: e }) } ```
Author
Owner

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

This issue might be a duplicate of existing issues. Please check:

  • #11697: Missing error handling in Share API fetch calls leads to silent failures
  • #11698: Unprotected JSON.parse in provider fetch wrapper can crash requests

These issues also address error handling gaps in the codebase that result in silent failures or crashes when errors aren't properly handled. You may want to review these related error handling issues to ensure a comprehensive solution across all affected modules.

@github-actions[bot] commented on GitHub (Feb 1, 2026): This issue might be a duplicate of existing issues. Please check: - #11697: Missing error handling in Share API fetch calls leads to silent failures - #11698: Unprotected JSON.parse in provider fetch wrapper can crash requests These issues also address error handling gaps in the codebase that result in silent failures or crashes when errors aren't properly handled. You may want to review these related error handling issues to ensure a comprehensive solution across all affected modules.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8273