diff --git a/src/main/services/FileStorage.ts b/src/main/services/FileStorage.ts index 58a6519fea..2244b97cb0 100644 --- a/src/main/services/FileStorage.ts +++ b/src/main/services/FileStorage.ts @@ -725,7 +725,10 @@ class FileStorage { } public openPath = async (_: Electron.IpcMainInvokeEvent, path: string): Promise => { - shell.openPath(path).catch((err) => logger.error('[IPC - Error] Failed to open file:', err)) + const resolved = await shell.openPath(path) + if (resolved !== '') { + throw new Error(resolved) + } } /** diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index 590057cdf1..f3d4b5181c 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -1177,6 +1177,9 @@ }, "document": "Document", "edit": "Edit", + "error": { + "open_path": "Failed to open path {{path}}" + }, "file": "File", "image": "Image", "name": "Name", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index bc47020350..dc1c82f03e 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -1177,6 +1177,9 @@ }, "document": "文档", "edit": "编辑", + "error": { + "open_path": "打开路径失败" + }, "file": "文件", "image": "图片", "name": "文件名", diff --git a/src/renderer/src/pages/home/ChatNavbar.tsx b/src/renderer/src/pages/home/ChatNavbar.tsx index 0d0dcce91d..378799779c 100644 --- a/src/renderer/src/pages/home/ChatNavbar.tsx +++ b/src/renderer/src/pages/home/ChatNavbar.tsx @@ -16,6 +16,7 @@ import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService' import { useAppDispatch } from '@renderer/store' import { setNarrowMode } from '@renderer/store/settings' import { ApiModel, Assistant, PermissionMode, Topic } from '@renderer/types' +import { formatErrorMessageWithPrefix } from '@renderer/utils/error' import { Tooltip } from 'antd' import { t } from 'i18next' import { Menu, PanelLeftClose, PanelRightClose, Search } from 'lucide-react' @@ -223,7 +224,15 @@ const SessionWorkspaceMeta: FC<{ agentId: string; sessionId: string }> = ({ agen key="path" text={firstAccessiblePath} className="max-w-60 transition-colors hover:border-primary hover:text-primary" - onClick={() => window.api.file.openPath(firstAccessiblePath)} + onClick={() => { + window.api.file + .openPath(firstAccessiblePath) + .catch((e) => + window.toast.error( + formatErrorMessageWithPrefix(e, t('files.error.open_path', { path: firstAccessiblePath })) + ) + ) + }} /> ) }