mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-02 02:09:03 +08:00
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:
parent
d2d5b4370c
commit
48b7bdb9ba
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1177,6 +1177,9 @@
|
||||
},
|
||||
"document": "Document",
|
||||
"edit": "Edit",
|
||||
"error": {
|
||||
"open_path": "Failed to open path {{path}}"
|
||||
},
|
||||
"file": "File",
|
||||
"image": "Image",
|
||||
"name": "Name",
|
||||
|
||||
@ -1177,6 +1177,9 @@
|
||||
},
|
||||
"document": "文档",
|
||||
"edit": "编辑",
|
||||
"error": {
|
||||
"open_path": "打开路径失败"
|
||||
},
|
||||
"file": "文件",
|
||||
"image": "图片",
|
||||
"name": "文件名",
|
||||
|
||||
@ -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 }))
|
||||
)
|
||||
)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user