优化 / 高 / 前端组件
src/components/common/ErrorBoundary.tsx
ErrorBoundary 捕获渲染错误后:
但未将错误上报到主进程:
class ErrorBoundary extends React.Component { componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { // 上报到主进程 window.metonaAPI?.reportError({ type: 'react_error_boundary', error: error.message, stack: error.stack, componentStack: errorInfo.componentStack, timestamp: Date.now(), }); // 同时 console.error 保留 console.error('ErrorBoundary caught:', error, errorInfo); } }
主进程添加 IPC:
ipcMain.handle('error:report', (event, payload) => { log.error('[Frontend Error]', payload); auditService.log({ type: 'frontend_error', payload }); });
可选集成 Sentry 等错误监控服务。
文件: src/components/common/ErrorBoundary.tsx + electron/preload.ts
electron/preload.ts
修复: preload 暴露 app.reportError(通过 ipcRenderer.send('error:report', payload) 单向发送);ErrorBoundary 的 componentDidCatch 中调用上报(含 type/error/stack/componentStack/timestamp),同时保留 console.error。
app.reportError
ipcRenderer.send('error:report', payload)
componentDidCatch
console.error
验证: tsc --noEmit 类型检查通过。
tsc --noEmit
No dependencies set.
The note is not visible to the blocked user.
问题类型
优化 / 高 / 前端组件
文件位置
src/components/common/ErrorBoundary.tsx问题描述
ErrorBoundary 捕获渲染错误后:
但未将错误上报到主进程:
影响
建议修复
主进程添加 IPC:
可选集成 Sentry 等错误监控服务。
修复说明
文件:
src/components/common/ErrorBoundary.tsx+electron/preload.ts修复: preload 暴露
app.reportError(通过ipcRenderer.send('error:report', payload)单向发送);ErrorBoundary 的componentDidCatch中调用上报(含 type/error/stack/componentStack/timestamp),同时保留console.error。验证:
tsc --noEmit类型检查通过。