2***@qq.com
2***@qq.com
  • 发布:2023-12-13 10:26
  • 更新:2023-12-13 15:46
  • 阅读:241

事务失败错误: transaction already commit

分类:uniCloud

产品分类: uniCloud/App

示例代码:

const transaction = await db.startTransaction()
try{
//写数据库代码略.........
await transaction.commit()
console.log(transaction succeeded)
return {
success: true,
order_no: order_no,
total_fee:orderHead.total_fee
}
}catch(e) {
await transaction.rollback()
console.error(transaction error, e)
return {
success: false,
error: e
}
}
//控制台结果,已经打印出 transaction succeeded,却抛出事务失败?
10:18:55.087 [本地调试]transaction succeeded uniCloud-aliyun/cloudfunctions
10:18:55.090 [本地调试]Error: 事务失败错误: transaction already commit
10:18:55.090 [本地调试] at new Promise (<anonymous>)

操作步骤:

const transaction = await db.startTransaction()
try{
//写数据库代码略.........
await transaction.commit()
console.log(transaction succeeded)
return {
success: true,
order_no: order_no,
total_fee:orderHead.total_fee
}
}catch(e) {
await transaction.rollback()
console.error(transaction error, e)
return {
success: false,
error: e
}
}
//控制台结果,已经打印出 transaction succeeded,却抛出事务失败?
10:18:55.087 [本地调试]transaction succeeded uniCloud-aliyun/cloudfunctions
10:18:55.090 [本地调试]Error: 事务失败错误: transaction already commit
10:18:55.090 [本地调试] at new Promise (<anonymous>)

预期结果:

return {
success: true,
order_no: order_no,
total_fee:orderHead.total_fee
}

实际结果:

return {
success: false,
error: e
}

bug描述:

const transaction = await db.startTransaction()
try{
//写数据库代码略.........
await transaction.commit()
console.log(transaction succeeded)
return {
success: true,
order_no: order_no,
total_fee:orderHead.total_fee
}
}catch(e) {
await transaction.rollback()
console.error(transaction error, e)
return {
success: false,
error: e
}
}
//控制台结果,已经打印出 transaction succeeded,却抛出事务失败?
10:18:55.087 [本地调试]transaction succeeded uniCloud-aliyun/cloudfunctions
10:18:55.090 [本地调试]Error: 事务失败错误: transaction already commit
10:18:55.090 [本地调试] at new Promise (<anonymous>)
本地调试:uni-h5.es.js:19612
POST http://127.0.0.1:7000/cloudfunctions/my-save-order 500 (Internal Server Error)

2023-12-13 10:26 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

catch里面的e打印一下

  • 2***@qq.com (作者)

    Error: 事务失败错误: transaction already commit

    2023-12-13 15:46

  • 2***@qq.com (作者)

    回复 2***@qq.com: 谢谢,放后面错误被屏蔽了

    2023-12-14 11:41

2***@qq.com

2***@qq.com (作者)

catch 打印出来的 Error: 事务失败错误: transaction already commit

要回复问题请先登录注册