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
2026-09-03 12:05:48 +08:00
parent 69cc8014a7
commit 4002f3cc5c
2 changed files with 14 additions and 8 deletions
+2 -2
View File
@@ -715,7 +715,7 @@ export function SubagentView(props: {
try {
sessions.openSubagent?.(address)
} catch (error) {
console.warn('[dsh-better-sidebar] openSubagent failed:', error)
console.error('[dsh-better-sidebar] openSubagent failed:', error)
}
}, [sessions, onOpenChild])
@@ -725,7 +725,7 @@ export function SubagentView(props: {
try {
sessions.open?.(rootId)
} catch (error) {
console.warn('[dsh-better-sidebar] open session failed:', error)
console.error('[dsh-better-sidebar] open session failed:', error)
}
}, [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. */
interface ConfirmState {
title: string
@@ -157,7 +163,7 @@ export function GitLens(props: GitLensProps) {
setLogEnded(logResult.length < LOG_BATCH)
} catch (reason) {
if (options.generation === refreshGeneration.current) {
setError(reason instanceof Error ? reason.message : String(reason))
setError(errorMessage(reason))
}
} finally {
if (options.loading && options.generation === refreshGeneration.current) setLoading(false)
@@ -219,7 +225,7 @@ export function GitLens(props: GitLensProps) {
await refreshTarget(target, { loading: !silent, generation })
} catch (reason) {
if (generation === refreshGeneration.current) {
setError(reason instanceof Error ? reason.message : String(reason))
setError(errorMessage(reason))
if (!silent) setLoading(false)
}
} finally {
@@ -289,7 +295,7 @@ export function GitLens(props: GitLensProps) {
if (next.length < LOG_BATCH) setLogEnded(true)
} catch (reason) {
if (generation === refreshGeneration.current && target === chosenPathRef.current) {
setCommitError(`${t('historyLoadError')}: ${reason instanceof Error ? reason.message : String(reason)}`)
setCommitError(`${t('historyLoadError')}: ${errorMessage(reason)}`)
}
} finally {
if (generation === refreshGeneration.current && target === chosenPathRef.current) setLogLoadingMore(false)
@@ -355,7 +361,7 @@ export function GitLens(props: GitLensProps) {
setCommitMsg('')
await refresh()
} catch (reason) {
setCommitError(reason instanceof Error ? reason.message : String(reason))
setCommitError(errorMessage(reason))
} finally {
setBusy(false)
}
@@ -369,7 +375,7 @@ export function GitLens(props: GitLensProps) {
await api.gitCheckout(gitScope, branch, selectedWorktree)
await refresh()
} catch (reason) {
setCommitError(`${t('checkoutError')}: ${reason instanceof Error ? reason.message : String(reason)}`)
setCommitError(`${t('checkoutError')}: ${errorMessage(reason)}`)
} finally {
setBusy(false)
}
@@ -384,7 +390,7 @@ export function GitLens(props: GitLensProps) {
await confirmState.onConfirm()
await refresh()
} catch (reason) {
setCommitError(reason instanceof Error ? reason.message : String(reason))
setCommitError(errorMessage(reason))
} finally {
setBusy(false)
}