From a1dc8ccb40133a1e59720488e267a08ae7734b7a Mon Sep 17 00:00:00 2001 From: Z User Date: Mon, 15 Jun 2026 23:29:38 +0000 Subject: [PATCH] fix: replace silent .catch(() => {}) with structured logging in prompt history Replace 3 silent .catch(() => {}) patterns in prompt/history.tsx with proper log.error() calls using the structured Log utility: - Self-heal rewrite: log error when rewriting corrupted history fails - Trim rewrite: log error when trimming history to max entries fails - Append: log error when appending new history entry fails The initial Filesystem.readText().catch(() => '') is intentionally kept as-is since it returns a valid default value for missing files. --- .../src/cli/cmd/tui/component/prompt/history.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx index 6426beeb..62684fc0 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/history.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" @@ -31,6 +31,7 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create name: "PromptHistory", init: () => { const historyPath = path.join(Global.Path.state, "prompt-history.jsonl") + const log = Log.create({ service: "prompt-history" }) onMount(async () => { const text = await Filesystem.readText(historyPath).catch(() => "") const lines = text @@ -51,7 +52,9 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create // 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(historyPath, content).catch(() => {}) + writeFile(historyPath, content).catch((error) => { + log.error("Failed to rewrite history file during self-heal", { path: historyPath, error }) + }) } }) @@ -97,11 +100,15 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create if (trimmed) { const content = store.history.map((line) => JSON.stringify(line)).join("\n") + "\n" - writeFile(historyPath, content).catch(() => {}) + writeFile(historyPath, content).catch((error) => { + log.error("Failed to trim history file", { path: historyPath, error }) + }) return } - appendFile(historyPath, JSON.stringify(entry) + "\n").catch(() => {}) + appendFile(historyPath, JSON.stringify(entry) + "\n").catch((error) => { + log.error("Failed to append to history file", { path: historyPath, error }) + }) }, } },