* refactor(editor-app): 改进架构和类型安全 * refactor(editor-app): 开始拆分 Inspector.tsx - 创建基础架构 * refactor(editor-app): 完成 Inspector.tsx 拆分 * refactor(editor-app): 优化 Inspector 类型定义,消除所有 any 使用 * refactor(editor): 实现可扩展的属性渲染器系统 * Potential fix for code scanning alert no. 231: Unused variable, import, function or class Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix(ci): 防止 Codecov 服务故障阻塞 CI 流程 --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import React from 'react';
|
|
import { ErrorBoundary } from './ErrorBoundary';
|
|
import { PluginError } from '../domain/errors';
|
|
|
|
interface PluginErrorBoundaryProps {
|
|
pluginId: string;
|
|
pluginName: string;
|
|
children: React.ReactNode;
|
|
onPluginError?: (pluginId: string, error: Error) => void;
|
|
}
|
|
|
|
export function PluginErrorBoundary({
|
|
pluginId,
|
|
pluginName,
|
|
children,
|
|
onPluginError
|
|
}: PluginErrorBoundaryProps): JSX.Element {
|
|
const handleError = (error: Error) => {
|
|
onPluginError?.(pluginId, error);
|
|
};
|
|
|
|
const renderFallback = (error: Error) => {
|
|
const pluginError =
|
|
error instanceof PluginError ? error : new PluginError(error.message, pluginId, pluginName, 'execute', error);
|
|
|
|
return (
|
|
<div
|
|
style={{
|
|
padding: '16px',
|
|
backgroundColor: '#fff3cd',
|
|
border: '1px solid #ffc107',
|
|
borderRadius: '4px',
|
|
margin: '10px'
|
|
}}
|
|
>
|
|
<h3 style={{ margin: '0 0 8px 0', color: '#856404' }}>插件错误</h3>
|
|
<p style={{ margin: '0 0 8px 0' }}>{pluginError.getUserMessage()}</p>
|
|
<small style={{ color: '#666' }}>插件ID: {pluginId}</small>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
return (
|
|
<ErrorBoundary fallback={renderFallback} onError={handleError}>
|
|
{children}
|
|
</ErrorBoundary>
|
|
);
|
|
}
|