From 4002f3cc5c2f875177f13eebedf03d303d5cb45a Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Thu, 3 Sep 2026 12:05:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor(client):=20=E7=BB=9F=E4=B8=80=20GitLen?= =?UTF-8?q?s=20=E9=94=99=E8=AF=AF=E5=BD=92=E4=B8=80=E5=8C=96=E4=B8=8E=20Su?= =?UTF-8?q?bagentView=20=E6=97=A5=E5=BF=97=E5=88=86=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 的断言,已核实。 --- src/client/SubagentView.tsx | 4 ++-- src/client/changes/GitLens.tsx | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/client/SubagentView.tsx b/src/client/SubagentView.tsx index 5ea2f74..3f28979 100644 --- a/src/client/SubagentView.tsx +++ b/src/client/SubagentView.tsx @@ -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]) diff --git a/src/client/changes/GitLens.tsx b/src/client/changes/GitLens.tsx index 71b7324..106d06e 100644 --- a/src/client/changes/GitLens.tsx +++ b/src/client/changes/GitLens.tsx @@ -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) }