feat(file): improve error handling for openPath operation

Add error message translation and proper error propagation when opening a file path fails
This commit is contained in:
icarus 2025-09-29 19:53:32 +08:00
parent d2d5b4370c
commit 48b7bdb9ba
4 changed files with 20 additions and 2 deletions

View File

@ -725,7 +725,10 @@ class FileStorage {
}
public openPath = async (_: Electron.IpcMainInvokeEvent, path: string): Promise<void> => {
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)
}
}
/**

View File

@ -1177,6 +1177,9 @@
},
"document": "Document",
"edit": "Edit",
"error": {
"open_path": "Failed to open path {{path}}"
},
"file": "File",
"image": "Image",
"name": "Name",

View File

@ -1177,6 +1177,9 @@
},
"document": "文档",
"edit": "编辑",
"error": {
"open_path": "打开路径失败"
},
"file": "文件",
"image": "图片",
"name": "文件名",

View File

@ -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 }))
)
)
}}
/>
)
}