From 7296a904e492b4a0528769aa757ed7f410957cf3 Mon Sep 17 00:00:00 2001 From: Z User Date: Mon, 15 Jun 2026 21:50:10 +0000 Subject: [PATCH] fix: add structured logging to frecency and stash file IO failures File writes in frecency.tsx (4 sites) and stash.tsx (5 sites) silently swallowed errors via .catch(() => {}). On read-only filesystems, permission errors, or full disks, these failures were completely invisible. Now logs at debug level so operators can diagnose IO issues without noise. The toast deduplication (PR #776) allows safely upgrading these to user-visible toasts in the future if needed. --- .../src/cli/cmd/tui/component/prompt/frecency.tsx | 6 +++--- .../src/cli/cmd/tui/component/prompt/stash.tsx | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/frecency.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/frecency.tsx index 929f3a07..e6c3c406 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/frecency.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/frecency.tsx @@ -1,6 +1,6 @@ import path from "path" import { Global } from "@/global" -import { Filesystem } from "@/util" +import { Filesystem, Log } from "@/util" import { onMount } from "solid-js" import { createStore } from "solid-js/store" import { createSimpleContext } from "../../context/helper" @@ -54,7 +54,7 @@ export const { use: useFrecency, provider: FrecencyProvider } = createSimpleCont if (sorted.length > 0) { const content = sorted.map((entry) => JSON.stringify(entry)).join("\n") + "\n" - writeFile(frecencyPath, content).catch(() => {}) + writeFile(frecencyPath, content).catch((e) => Log.Default.debug("frecency write failed", { error: String(e) })) } }) @@ -77,7 +77,7 @@ export const { use: useFrecency, provider: FrecencyProvider } = createSimpleCont .slice(0, MAX_FRECENCY_ENTRIES) setStore("data", Object.fromEntries(sorted)) const content = sorted.map(([path, entry]) => JSON.stringify({ path, ...entry })).join("\n") + "\n" - writeFile(frecencyPath, content).catch(() => {}) + writeFile(frecencyPath, content).catch((e) => Log.Default.debug("frecency trim failed", { error: String(e) })) } } diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/stash.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/stash.tsx index 84ba6233..c6ca2fd0 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/stash.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/stash.tsx @@ -1,6 +1,6 @@ import path from "path" import { Global } from "@/global" -import { Filesystem } from "@/util" +import { Filesystem, Log } from "@/util" import { onMount } from "solid-js" import { createStore, produce, unwrap } from "solid-js/store" import { createSimpleContext } from "../../context/helper" @@ -39,7 +39,7 @@ export const { use: usePromptStash, provider: PromptStashProvider } = createSimp // Rewrite file with only valid entries to self-heal corruption if (lines.length > 0) { const content = lines.map((line) => JSON.stringify(line)).join("\n") + "\n" - writeFile(stashPath, content).catch(() => {}) + writeFile(stashPath, content).catch((e) => Log.Default.debug("stash file write failed", { error: String(e) })) } }) @@ -66,11 +66,11 @@ export const { use: usePromptStash, provider: PromptStashProvider } = createSimp if (trimmed) { const content = store.entries.map((line) => JSON.stringify(line)).join("\n") + "\n" - writeFile(stashPath, content).catch(() => {}) + writeFile(stashPath, content).catch((e) => Log.Default.debug("stash file write failed", { error: String(e) })) return } - appendFile(stashPath, JSON.stringify(stash) + "\n").catch(() => {}) + appendFile(stashPath, JSON.stringify(stash) + "\n").catch((e) => Log.Default.debug("stash file write failed", { error: String(e) })) }, pop() { if (store.entries.length === 0) return undefined @@ -82,7 +82,7 @@ export const { use: usePromptStash, provider: PromptStashProvider } = createSimp ) const content = store.entries.length > 0 ? store.entries.map((line) => JSON.stringify(line)).join("\n") + "\n" : "" - writeFile(stashPath, content).catch(() => {}) + writeFile(stashPath, content).catch((e) => Log.Default.debug("stash file write failed", { error: String(e) })) return entry }, remove(index: number) { @@ -94,7 +94,7 @@ export const { use: usePromptStash, provider: PromptStashProvider } = createSimp ) const content = store.entries.length > 0 ? store.entries.map((line) => JSON.stringify(line)).join("\n") + "\n" : "" - writeFile(stashPath, content).catch(() => {}) + writeFile(stashPath, content).catch((e) => Log.Default.debug("stash file write failed", { error: String(e) })) }, } },