DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
refactor: introduce shared silence() utility for intentional error swallowing
coderstory434c360d82f2
diff --git a/src/components/config-backup.tsx b/src/components/config-backup.tsxindex d8916473..c5adde4b 100644--- a/src/components/config-backup.tsx+++ b/src/components/config-backup.tsx@@ -6,6 +6,7 @@ import { useState } from 'react'import { useTranslation } from 'react-i18next'import { If } from 'react-if-lite'import { store } from '@/store'+import { silence } from '@/utils/silence'import { toast } from '@/utils/toast'import { useBackups } from '../hooks/use-backup'import { Item } from './item'@@ -52,7 +53,8 @@ export function ConfigBackup({ onBack }: ConfigBackupProps) {),})}- catch {+ catch (e) {+ silence(e, 'backup: dialog cancelled')return}try {@@ -99,7 +101,8 @@ export function ConfigBackup({ onBack }: ConfigBackupProps) {),})}- catch {+ catch (e) {+ silence(e, 'backup: dialog cancelled')return}try {@@ -125,7 +128,8 @@ export function ConfigBackup({ onBack }: ConfigBackupProps) {confirmText: t('backup.delete'),})}- catch {+ catch (e) {+ silence(e, 'backup: dialog cancelled')return}try {diff --git a/src/components/config-core.tsx b/src/components/config-core.tsxindex 5e4aba1d..38d1d4ec 100644--- a/src/components/config-core.tsx+++ b/src/components/config-core.tsx@@ -7,6 +7,7 @@ import { Fragment, useState } from 'react'import { useTranslation } from 'react-i18next'import { If } from 'react-if-lite'import { store } from '@/store'+import { silence } from '@/utils/silence'import { toast } from '@/utils/toast'import { useDshCores } from '../hooks/use-dsh-cores'import { DownloadCoreDialog } from './download-core-dialog'@@ -102,7 +103,8 @@ export function ConfigCore() {),})}- catch {+ catch (e) {+ silence(e, 'core switch: dialog cancelled')return}try {@@ -118,8 +120,8 @@ export function ConfigCore() {await store.harness.restart()toast.close(key)}- catch {- // 重启失败已由应用错误态呈现,这里静默吞掉以免重复弹错。+ catch (e) {+ silence(e, 'core switch: restart failure already shown by app error state')}}catch (err) {@@ -175,7 +177,8 @@ export function ConfigCore() {confirmText: t('core.uninstall'),})}- catch {+ catch (e) {+ silence(e, 'core switch: dialog cancelled')return}try {diff --git a/src/components/config-plugin.tsx b/src/components/config-plugin.tsxindex 387c080b..1572c5af 100644--- a/src/components/config-plugin.tsx+++ b/src/components/config-plugin.tsx@@ -9,6 +9,7 @@ import { If } from 'react-if-lite'import { tv } from 'tailwind-variants'import { useStore } from 'valtio-define'import { store } from '@/store'+import { silence } from '@/utils/silence'import { toast } from '@/utils/toast'import { useDshPlugins } from '../hooks/use-dsh-plugins'import { Ellipsis as TextEllipsis } from './ellipsis'@@ -158,8 +159,8 @@ export function ConfigPlugin() {try {await upgrade.mutateAsync(id)}- catch {- // 错误提示已由 mutation 的 onError 处理+ catch (e) {+ silence(e, 'plugin upgrade: error already shown by mutation onError')}finally {setBusy(null)@@ -184,15 +185,15 @@ export function ConfigPlugin() {confirmText: t('plugins.uninstall'),})}- catch {+ catch (e) {+ silence(e, 'plugin remove: dialog cancelled')return}- setBusy({ id, action: 'remove' })try {await remove.mutateAsync(id)}- catch {- // 错误提示已由 mutation 的 onError 处理+ catch (e) {+ silence(e, 'plugin upgrade: error already shown by mutation onError')}finally {setBusy(null)@@ -209,8 +210,8 @@ export function ConfigPlugin() {try {await disable.mutateAsync(id)}- catch {- // 错误提示已由 mutation 的 onError 处理+ catch (e) {+ silence(e, 'plugin upgrade: error already shown by mutation onError')}finally {setBusy(null)@@ -226,8 +227,8 @@ export function ConfigPlugin() {try {await enable.mutateAsync(id)}- catch {- // 错误提示已由 mutation 的 onError 处理+ catch (e) {+ silence(e, 'plugin upgrade: error already shown by mutation onError')}finally {setBusy(null)@@ -253,7 +254,8 @@ export function ConfigPlugin() {confirmText: t('plugins.snapshot_overwrite_confirm'),})}- catch {+ catch (e) {+ silence(e, 'plugin snapshot: dialog cancelled')return}}@@ -261,8 +263,8 @@ export function ConfigPlugin() {try {await snapshot.mutateAsync(id)}- catch {- // 错误提示已由 mutation 的 onError 处理+ catch (e) {+ silence(e, 'plugin upgrade: error already shown by mutation onError')}finally {setBusy(null)@@ -284,10 +286,10 @@ export function ConfigPlugin() {confirmText: t('plugins.restore'),})}- catch {+ catch (e) {+ silence(e, 'plugin restore: dialog cancelled')return}- setBusy({ id, action: 'restore' })try {await restore.mutateAsync(id)// 还原期间后端已停止服务:复用 config-backup 的「重启服务」toast 交互@@ -303,8 +305,8 @@ export function ConfigPlugin() {},})}- catch {- // 错误提示已由 mutation 的 onError 处理+ catch (e) {+ silence(e, 'plugin upgrade: error already shown by mutation onError')}finally {setBusy(null)@@ -326,15 +328,15 @@ export function ConfigPlugin() {confirmText: t('plugins.snapshot_delete_confirm'),})}- catch {+ catch (e) {+ silence(e, 'plugin delete-snapshot: dialog cancelled')return}- setBusy({ id, action: 'delete-snapshot' })try {await deleteSnapshot.mutateAsync(id)}- catch {- // 错误提示已由 mutation 的 onError 处理+ catch (e) {+ silence(e, 'plugin upgrade: error already shown by mutation onError')}finally {setBusy(null)diff --git a/src/components/config-profile.tsx b/src/components/config-profile.tsxindex c0019b48..402fe455 100644--- a/src/components/config-profile.tsx+++ b/src/components/config-profile.tsx@@ -6,6 +6,7 @@ import { useState } from 'react'import { useTranslation } from 'react-i18next'import { If } from 'react-if-lite'import { store } from '@/store'+import { silence } from '@/utils/silence'import { toast } from '@/utils/toast'import { useDshProfiles } from '../hooks/use-dsh-profiles'import { ConfigBackup } from './config-backup'@@ -94,11 +95,10 @@ export function ConfigProfile() {),})}- catch {+ catch (e) {+ silence(e, 'profile activate: dialog cancelled')return}- try {- await activateProfile(id)const key = toast(t('profiles.activate_toast', { name: target.name }), {variant: 'accent',description: t('profiles.activate_restart_hint'),@@ -160,12 +160,10 @@ export function ConfigProfile() {confirmText: t('profiles.remove_confirm'),})}- catch {+ catch (e) {+ silence(e, 'profile remove: dialog cancelled')return}- try {- // 删除成功后列表已移除该档案,UI 本身就有变化,不再弹成功 toast- await removeProfile(id)}catch (err) {console.error('[ConfigProfile] remove failed:', err)diff --git a/src/components/desktop-about-dialog.tsx b/src/components/desktop-about-dialog.tsxindex 7a40244d..7ba3c8f8 100644--- a/src/components/desktop-about-dialog.tsx+++ b/src/components/desktop-about-dialog.tsx@@ -7,6 +7,7 @@ import { useEffect } from 'react'import { useTranslation } from 'react-i18next'import { useStore } from 'valtio-define'import { store } from '@/store'+import { silence } from '@/utils/silence'import { Info } from './info'export interface DesktopAboutDialogProps extends PropsWithOverlays {}@@ -83,7 +84,8 @@ function formatDate(iso: string): string {return isoreturn d.toLocaleDateString()}- catch {+ catch (e) {+ silence(e, 'about dialog: date parsing failed, falling back to raw ISO')return iso}}diff --git a/src/components/plugin-recovery.tsx b/src/components/plugin-recovery.tsxindex c0163085..76b2d2b3 100644--- a/src/components/plugin-recovery.tsx+++ b/src/components/plugin-recovery.tsx@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next'import { If } from 'react-if-lite'import { useStore } from 'valtio-define'import { store } from '@/store'+import { silence } from '@/utils/silence'/** 插件异常修复界面最多自动提示的次数(与 store 的 MAX_RECOVERY_ATTEMPTS 一致) */const MAX_RECOVERY_ATTEMPTS = 3@@ -50,7 +51,8 @@ export function PluginRecovery({ fullScreen = false }: { fullScreen?: boolean })const r = await invoke<{ exists: boolean }>('get_plugin_backup', { id })return r.exists ? id : null}- catch {+ catch (e) {+ silence(e, 'plugin recovery: backup check failed, will retry')return null}}))diff --git a/src/utils/silence.ts b/src/utils/silence.tsnew file mode 100644index 00000000..53e20c59--- /dev/null+++ b/src/utils/silence.ts@@ -0,0 +1,15 @@+/**+ * Shared utility for intentionally swallowed errors in catch blocks.+ *+ * Use in catch blocks where the error is intentionally swallowed because it's+ * already handled elsewhere (e.g., by an error boundary, mutation onError, or+ * app error state).+ *+ * In dev mode, logs to console.debug with the reason for visibility.+ * In production, does nothing (truly silent).+ */+export function silence(error: unknown, reason?: string): void {+ if (import.meta.env.DEV) {+ console.debug(reason ? `[silenced] ${reason}` : '[silenced]', error)+ }+}