fix: 修复日志输出中的循环引用和undefined错误
- 修复executeTemplate中result.length访问undefined的问题 - 添加安全的类型检查和结果输出 - 修复JSON.stringify循环引用错误 - 改进异常处理的安全性 - 优化模板信息输出,避免复杂对象序列化问题 - 增强错误处理的健壮性
This commit is contained in:
parent
52c22ab9bd
commit
457e69f46b
|
|
@ -19,7 +19,14 @@ export class AppController {
|
||||||
const templates = this.tempalte.getAllTemplates();
|
const templates = this.tempalte.getAllTemplates();
|
||||||
|
|
||||||
console.log(`✅ [获取模板列表] 成功获取 ${templates.length} 个模板`);
|
console.log(`✅ [获取模板列表] 成功获取 ${templates.length} 个模板`);
|
||||||
console.log(`📊 模板列表: ${templates.map(t => t.code || t.name).join(', ')}`);
|
|
||||||
|
// 安全地输出模板列表
|
||||||
|
try {
|
||||||
|
const templateNames = templates.map(t => t?.code || t?.name || '[未命名模板]').filter(Boolean);
|
||||||
|
console.log(`📊 模板列表: ${templateNames.join(', ')}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`📊 模板列表: [无法获取模板名称]`);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: true,
|
status: true,
|
||||||
|
|
@ -37,7 +44,19 @@ export class AppController {
|
||||||
|
|
||||||
if (template) {
|
if (template) {
|
||||||
console.log(`✅ [获取模板] 模板找到: ${template.name || templateCode}`);
|
console.log(`✅ [获取模板] 模板找到: ${template.name || templateCode}`);
|
||||||
console.log(`📋 模板信息: ${JSON.stringify(template, null, 2)}`);
|
|
||||||
|
// 安全地输出模板信息,避免循环引用
|
||||||
|
try {
|
||||||
|
const templateInfo = {
|
||||||
|
code: template.code,
|
||||||
|
name: template.name,
|
||||||
|
description: template.description,
|
||||||
|
// 只输出基本信息,避免复杂对象
|
||||||
|
};
|
||||||
|
console.log(`📋 模板信息: ${JSON.stringify(templateInfo, null, 2)}`);
|
||||||
|
} catch (jsonError) {
|
||||||
|
console.log(`📋 模板信息: [无法序列化的复杂对象]`);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: true,
|
status: true,
|
||||||
|
|
@ -90,7 +109,17 @@ export class AppController {
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
console.log(`🎉 [模板执行] 执行成功`);
|
console.log(`🎉 [模板执行] 执行成功`);
|
||||||
console.log(`📊 执行结果长度: ${result.length} 字符`);
|
console.log(`📊 执行结果类型: ${typeof result}`);
|
||||||
|
|
||||||
|
// 安全地获取结果长度
|
||||||
|
if (typeof result === 'string') {
|
||||||
|
console.log(`📊 执行结果长度: ${result.length} 字符`);
|
||||||
|
} else if (result && typeof result === 'object') {
|
||||||
|
console.log(`📊 执行结果: [对象类型]`);
|
||||||
|
} else {
|
||||||
|
console.log(`📊 执行结果: ${result}`);
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`⏱️ 执行耗时: ${executionTime}ms`);
|
console.log(`⏱️ 执行耗时: ${executionTime}ms`);
|
||||||
console.log(`✨ 完成时间: ${new Date().toISOString()}`);
|
console.log(`✨ 完成时间: ${new Date().toISOString()}`);
|
||||||
|
|
||||||
|
|
@ -101,7 +130,8 @@ export class AppController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`⚠️ [模板执行] 执行完成但结果为空`);
|
console.log(`⚠️ [模板执行] 执行完成但结果为空或undefined`);
|
||||||
|
console.log(`📊 结果值: ${result}`);
|
||||||
console.log(`⏱️ 执行耗时: ${executionTime}ms`);
|
console.log(`⏱️ 执行耗时: ${executionTime}ms`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -112,15 +142,20 @@ export class AppController {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const executionTime = Date.now() - startTime;
|
const executionTime = Date.now() - startTime;
|
||||||
console.log(`💥 [模板执行] 执行异常`);
|
console.log(`💥 [模板执行] 执行异常`);
|
||||||
console.log(`❌ 错误信息: ${e.message}`);
|
console.log(`❌ 错误信息: ${e?.message || '未知错误'}`);
|
||||||
console.log(`📍 错误堆栈: ${e.stack}`);
|
|
||||||
|
// 安全地输出错误堆栈
|
||||||
|
if (e?.stack) {
|
||||||
|
console.log(`📍 错误堆栈: ${e.stack}`);
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`⏱️ 执行耗时: ${executionTime}ms`);
|
console.log(`⏱️ 执行耗时: ${executionTime}ms`);
|
||||||
console.log(`🔚 异常时间: ${new Date().toISOString()}`);
|
console.log(`🔚 异常时间: ${new Date().toISOString()}`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: false,
|
status: false,
|
||||||
data: null,
|
data: null,
|
||||||
msg: e.message
|
msg: e?.message || '模板执行异常'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue