From a5aa1fd82be7f5f39d37d6ee2e620df7684771d1 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 21 Jul 2026 15:31:05 +0800 Subject: [PATCH] fix(providers): surface import errors and refresh list on failed import Tauri invoke rejects with the backend's serialized error string, not an Error object, so reading `.message` produced an empty toast for every failed live-config import. Route the rejection through extractErrorMessage with a generic i18n fallback. Also invalidate the providers query on import failure: the import command can have visible side effects before erroring (e.g. GrokBuild ensures its official entry prior to a failing import), and the list must reflect them without a manual refresh. --- src/components/providers/ProviderList.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/providers/ProviderList.tsx b/src/components/providers/ProviderList.tsx index 62edad709..dbb6be0ea 100644 --- a/src/components/providers/ProviderList.tsx +++ b/src/components/providers/ProviderList.tsx @@ -20,6 +20,7 @@ import { toast } from "sonner"; import type { Provider } from "@/types"; import type { AppId } from "@/lib/api"; import { providersApi } from "@/lib/api/providers"; +import { extractErrorMessage } from "@/utils/errorUtils"; import { useDragSort } from "@/hooks/useDragSort"; import { useOpenClawLiveProviderIds, @@ -239,8 +240,13 @@ export function ProviderList({ toast.info(t("provider.noProviders")); } }, - onError: (error: Error) => { - toast.error(error.message); + onError: (error: unknown) => { + // Tauri invoke 的 reject 值是后端序列化出的纯字符串而非 Error 对象, + // 取 .message 只会得到 undefined(空 toast)。 + toast.error(extractErrorMessage(error) || t("settings.importFailed")); + // 导入失败前也可能已产生需要上屏的副作用:GrokBuild 官方登录态下点 + // 导入,命令层会先补种官方条目、随后才因 live 不可导入而报错。 + queryClient.invalidateQueries({ queryKey: ["providers", appId] }); }, });