|
|
@@ -10,6 +10,20 @@ import { writeFileSync } from 'fs';
|
|
|
import fs from 'fs';
|
|
|
import path from 'path';
|
|
|
|
|
|
+// 导入 safeStringify 函数来处理对象序列化
|
|
|
+function safeStringify(obj) {
|
|
|
+ const cache = new Set();
|
|
|
+ return JSON.stringify(obj, (key, value) => {
|
|
|
+ if (typeof value === 'object' && value !== null) {
|
|
|
+ if (cache.has(value)) {
|
|
|
+ return '[Circular]';
|
|
|
+ }
|
|
|
+ cache.add(value);
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
// -------------- 全局错误处理 --------------
|
|
|
process.on('uncaughtException', (error) => {
|
|
|
writeLog('fatal', `未捕获的异常: ${error.message}\n${error.stack}`);
|
|
|
@@ -25,11 +39,11 @@ process.on('unhandledRejection', (reason, promise) => {
|
|
|
|
|
|
// 监听应用崩溃
|
|
|
app.on('render-process-gone', (event, webContents, details) => {
|
|
|
- writeLog('fatal', `渲染进程崩溃: ${JSON.stringify(details)}`);
|
|
|
+ writeLog('fatal', `渲染进程崩溃: ${safeStringify(details)}`);
|
|
|
});
|
|
|
|
|
|
app.on('child-process-gone', (event, childProcess, details) => {
|
|
|
- writeLog('error', `子进程崩溃: ${JSON.stringify(details)}`);
|
|
|
+ writeLog('error', `子进程崩溃: ${safeStringify(details)}`);
|
|
|
});
|
|
|
|
|
|
// -------------- 构造 ESM 版 __dirname --------------
|