refactor(hooks): fix empty catches and remove AI slop from code comments

This commit is contained in:
YeonGyu-Kim
2026-04-03 21:37:16 +09:00
parent 6b431c5522
commit 5c7299830d
17 changed files with 900 additions and 565 deletions
@@ -11,6 +11,27 @@ import type { Client } from "./client"
import { PLACEHOLDER_TEXT } from "./message-builder"
import { incrementEmptyContentAttempt } from "./state"
import { fixEmptyMessagesWithSDK } from "./empty-content-recovery-sdk"
import { log } from "../../shared/logger"
async function showToastSafely(
client: Client,
body: {
title: string
message: string
variant: "error" | "warning" | "success"
duration: number
},
failureContext: string,
): Promise<void> {
try {
await client.tui.showToast({ body })
} catch (error) {
log(`[auto-compact] failed to show toast: ${failureContext}`, {
title: body.title,
error: error instanceof Error ? error.message : String(error),
})
}
}
export async function fixEmptyMessages(params: {
sessionID: string
@@ -32,30 +53,30 @@ export async function fixEmptyMessages(params: {
})
if (!result.fixed && result.scannedEmptyCount === 0) {
await params.client.tui
.showToast({
body: {
title: "Empty Content Error",
message: "No empty messages found in storage. Cannot auto-recover.",
variant: "error",
duration: 5000,
},
})
.catch(() => {})
await showToastSafely(
params.client,
{
title: "Empty Content Error",
message: "No empty messages found in storage. Cannot auto-recover.",
variant: "error",
duration: 5000,
},
"sqlite empty message not found",
)
return false
}
if (result.fixed) {
await params.client.tui
.showToast({
body: {
title: "Session Recovery",
message: `Fixed ${result.fixedMessageIds.length} empty message(s). Retrying...`,
variant: "warning",
duration: 3000,
},
})
.catch(() => {})
await showToastSafely(
params.client,
{
title: "Session Recovery",
message: `Fixed ${result.fixedMessageIds.length} empty message(s). Retrying...`,
variant: "warning",
duration: 3000,
},
"sqlite empty message fixed",
)
}
return result.fixed
@@ -83,16 +104,16 @@ export async function fixEmptyMessages(params: {
const emptyTextPartIds = findMessagesWithEmptyTextParts(params.sessionID)
const allIds = [...new Set([...emptyMessageIds, ...emptyTextPartIds])]
if (allIds.length === 0) {
await params.client.tui
.showToast({
body: {
title: "Empty Content Error",
message: "No empty messages found in storage. Cannot auto-recover.",
variant: "error",
duration: 5000,
},
})
.catch(() => {})
await showToastSafely(
params.client,
{
title: "Empty Content Error",
message: "No empty messages found in storage. Cannot auto-recover.",
variant: "error",
duration: 5000,
},
"empty message not found",
)
return false
}
@@ -112,16 +133,16 @@ export async function fixEmptyMessages(params: {
}
if (fixed) {
await params.client.tui
.showToast({
body: {
title: "Session Recovery",
message: `Fixed ${fixedMessageIds.length} empty message(s). Retrying...`,
variant: "warning",
duration: 3000,
},
})
.catch(() => {})
await showToastSafely(
params.client,
{
title: "Session Recovery",
message: `Fixed ${fixedMessageIds.length} empty message(s). Retrying...`,
variant: "warning",
duration: 3000,
},
"empty messages fixed",
)
}
return fixed