fix: 为错误对象添加name和stack字段

在工具执行失败和数据库升级时,为错误对象补充name和stack字段以提供更完整的错误信息
This commit is contained in:
icarus 2025-09-04 01:47:48 +08:00
parent 1cab37467d
commit baa7a1b9a6
2 changed files with 19 additions and 6 deletions

View File

@ -136,7 +136,7 @@ export async function upgradeToV7(tx: Transaction): Promise<void> {
content: mcpTool.response,
error:
mcpTool.status !== 'done'
? { message: 'MCP Tool did not complete', originalStatus: mcpTool.status }
? { message: 'MCP Tool did not complete', originalStatus: mcpTool.status, name: null, stack: null }
: undefined,
createdAt: oldMessage.createdAt,
metadata: { rawMcpToolResponse: mcpTool }
@ -263,10 +263,18 @@ export async function upgradeToV7(tx: Transaction): Promise<void> {
// 10. Error Block (Status is ERROR)
if (oldMessage.error && typeof oldMessage.error === 'object' && Object.keys(oldMessage.error).length > 0) {
if (isEmpty(oldMessage.content)) {
const block = createErrorBlock(oldMessage.id, oldMessage.error, {
createdAt: oldMessage.createdAt,
status: MessageBlockStatus.ERROR // Error block status is ERROR
})
const block = createErrorBlock(
oldMessage.id,
{
message: oldMessage.error?.message ?? null,
name: oldMessage.error?.name ?? null,
stack: oldMessage.error?.stack ?? null
},
{
createdAt: oldMessage.createdAt,
status: MessageBlockStatus.ERROR // Error block status is ERROR
}
)
blocksToCreate.push(block)
messageBlockIds.push(block.id)
}

View File

@ -97,7 +97,12 @@ export const createToolCallbacks = (deps: ToolCallbacksDependencies) => {
}
if (finalStatus === MessageBlockStatus.ERROR) {
changes.error = { message: `Tool execution failed/error`, details: toolResponse.response }
changes.error = {
message: `Tool execution failed/error`,
details: toolResponse.response,
name: null,
stack: null
}
}
blockManager.smartBlockUpdate(existingBlockId, changes, MessageBlockType.TOOL, true)