Skip to content

[BUG] Audit and remove 104 silent .catch(() => {}) in production code #331

Description

@moizlatif7

Summary

The CLI production code silently swallows errors in 104 places using .catch(() => {}) (or equivalents like .catch(() => undefined), .catch((_) => {})). This is the single most likely explanation for user reports of vague "unreliability" — errors that would help diagnose problems are dropped without any log, telemetry, or user-visible message.

Reproduction / Measurement

grep -rn '\.catch(() => {})\|\.catch((_) => {})\|\.catch(() => undefined)\|\.catch(() => null)' \
packages/opencode/src/ packages/anr-core/src/ packages/llm/src/ \
| grep -v node_modules | grep -v test| wc -l
# → 104

Representative Examples

File:lineWhat's swallowed
packages/opencode/src/config/config.ts:274Config-loading failure
packages/opencode/src/lsp/lsp.ts:362LSP initialization failure
packages/opencode/src/lsp/server.ts:675fs.chmod failure on LSP binary
packages/opencode/src/lsp/server.ts:1055fs.chmod on clangd binary
packages/opencode/src/lsp/server.ts:1058fs.unlink for symlink cleanup
packages/opencode/src/lsp/server.ts:1059fs.symlink for clangd
packages/opencode/src/lsp/server.ts:1347Launcher script chmod
packages/opencode/src/plugin/tui/runtime.ts:273PluginMeta.setTheme failure
packages/opencode/src/plugin/tui/runtime.ts:302Filesystem.write failure
packages/opencode/src/plugin/tui/runtime.ts:307Plugin runtime setup
packages/opencode/src/plugin/tui/runtime.ts:680Async wait
packages/opencode/src/plugin/xai.ts:606xAI provider network
packages/opencode/src/plugin/digitalocean.ts:314DigitalOcean provider
packages/opencode/src/plugin/snowflake-cortex.ts:338,375Snowflake Cortex provider
packages/opencode/src/cli/upgrade.ts:52Auto-update result emit

Policy — What Each Should Become

  1. Truly ignorable (e.g., best-effort cleanup that legitimately can't fail loudly): replace with .catch((err) => log.debug({ msg: "ignored", err })) — never bare {}.
  2. User action needed (config load, auth, provider init): re-throw or wrap in a typed error and surface to the TUI.
  3. Diagnostic-only (telemetry, cache): keep silent but record via OTEL.

Acceptance Criteria

  • Net count of bare .catch(() => {}) in prod code drops to ≤10, and each remaining occurrence has an inline comment explaining why silence is correct.
  • All swallowed errors that indicate user-actionable problems (auth failure, config invalid, provider unreachable) become user-visible.
  • A lint rule (Biome or oxlint) fires on new bare .catch(() => {}) unless justified.
  • Regression tests: at least 3 scenarios where a previously-silent failure now surfaces to the caller.

Related

Scope

In scope:packages/opencode/src/, packages/anr-core/src/, packages/llm/src/
Out of scope: test files, tools/scripts, and packages/core/src/ (already largely uses Effect's typed errors)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions