refactor(client): 统一 GitLens 错误归一化与 SubagentView 日志分级

- GitLens.tsx:六处 catch 里的 reason instanceof Error ?
  reason.message : String(reason)(refreshTarget/refresh/loadMoreLog/
  commit/checkout/runConfirmed)收敛为模块级 errorMessage(),
  两处模板字符串插值场景(historyLoadError/checkoutError 前缀)
  同样复用;归一化表达式与输出文本逐字不变。
- SubagentView.tsx:openSubagent/open session 失败的 console.warn
  改为 console.error,与同严重度失败路径对齐(Sidebar.tsx tab
  badge、TerminalView.tsx xterm open、service.ts urlTarget/plugin
  callback 均为 console.error);前缀与消息文本不变。tests/ 无任何
  钉 console.warn 的断言,已核实。
This commit is contained in:
Menghuan1918 committed 2026-09-03 12:05:48 +08:00
1 parent 69cc8014a7
commit 4002f3cc5c
2 files changed
+14 -8

No files matched your search

+2 -2
View File
@@ -715,7 +715,7 @@ export function SubagentView(props: {
try { try {
sessions.openSubagent?.(address) sessions.openSubagent?.(address)
} catch (error) { } catch (error) {
console.warn('[dsh-better-sidebar] openSubagent failed:', error) console.error('[dsh-better-sidebar] openSubagent failed:', error)
} }
}, [sessions, onOpenChild]) }, [sessions, onOpenChild])
@@ -725,7 +725,7 @@ export function SubagentView(props: {
try { try {
sessions.open?.(rootId) sessions.open?.(rootId)
} catch (error) { } catch (error) {
console.warn('[dsh-better-sidebar] open session failed:', error) console.error('[dsh-better-sidebar] open session failed:', error)
} }
}, [sessions, rootId]) }, [sessions, rootId])
+12 -6
View File
@@ -64,6 +64,12 @@ function refNames(refs: string): string[] {
)] )]
} }
/** One thrown value as display text (every error banner/row here normalizes
* through this so non-Error rejections never render as '[object Object]'). */
function errorMessage(reason: unknown): string {
return reason instanceof Error ? reason.message : String(reason)
}
/** The pending destructive action (discard / revert / cherry-pick), gated by a confirm modal. */ /** The pending destructive action (discard / revert / cherry-pick), gated by a confirm modal. */
interface ConfirmState { interface ConfirmState {
title: string title: string
@@ -157,7 +163,7 @@ export function GitLens(props: GitLensProps) {
setLogEnded(logResult.length < LOG_BATCH) setLogEnded(logResult.length < LOG_BATCH)
} catch (reason) { } catch (reason) {
if (options.generation === refreshGeneration.current) { if (options.generation === refreshGeneration.current) {
setError(reason instanceof Error ? reason.message : String(reason)) setError(errorMessage(reason))
} }
} finally { } finally {
if (options.loading && options.generation === refreshGeneration.current) setLoading(false) if (options.loading && options.generation === refreshGeneration.current) setLoading(false)
@@ -219,7 +225,7 @@ export function GitLens(props: GitLensProps) {
await refreshTarget(target, { loading: !silent, generation }) await refreshTarget(target, { loading: !silent, generation })
} catch (reason) { } catch (reason) {
if (generation === refreshGeneration.current) { if (generation === refreshGeneration.current) {
setError(reason instanceof Error ? reason.message : String(reason)) setError(errorMessage(reason))
if (!silent) setLoading(false) if (!silent) setLoading(false)
} }
} finally { } finally {
@@ -289,7 +295,7 @@ export function GitLens(props: GitLensProps) {
if (next.length < LOG_BATCH) setLogEnded(true) if (next.length < LOG_BATCH) setLogEnded(true)
} catch (reason) { } catch (reason) {
if (generation === refreshGeneration.current && target === chosenPathRef.current) { if (generation === refreshGeneration.current && target === chosenPathRef.current) {
setCommitError(`${t('historyLoadError')}: ${reason instanceof Error ? reason.message : String(reason)}`) setCommitError(`${t('historyLoadError')}: ${errorMessage(reason)}`)
} }
} finally { } finally {
if (generation === refreshGeneration.current && target === chosenPathRef.current) setLogLoadingMore(false) if (generation === refreshGeneration.current && target === chosenPathRef.current) setLogLoadingMore(false)
@@ -355,7 +361,7 @@ export function GitLens(props: GitLensProps) {
setCommitMsg('') setCommitMsg('')
await refresh() await refresh()
} catch (reason) { } catch (reason) {
setCommitError(reason instanceof Error ? reason.message : String(reason)) setCommitError(errorMessage(reason))
} finally { } finally {
setBusy(false) setBusy(false)
} }
@@ -369,7 +375,7 @@ export function GitLens(props: GitLensProps) {
await api.gitCheckout(gitScope, branch, selectedWorktree) await api.gitCheckout(gitScope, branch, selectedWorktree)
await refresh() await refresh()
} catch (reason) { } catch (reason) {
setCommitError(`${t('checkoutError')}: ${reason instanceof Error ? reason.message : String(reason)}`) setCommitError(`${t('checkoutError')}: ${errorMessage(reason)}`)
} finally { } finally {
setBusy(false) setBusy(false)
} }
@@ -384,7 +390,7 @@ export function GitLens(props: GitLensProps) {
await confirmState.onConfirm() await confirmState.onConfirm()
await refresh() await refresh()
} catch (reason) { } catch (reason) {
setCommitError(reason instanceof Error ? reason.message : String(reason)) setCommitError(errorMessage(reason))
} finally { } finally {
setBusy(false) setBusy(false)
} }