- 当前 Bug 的表现(可附上截图)
在云开发控制台测试云函数时,错误提示如下:
测试结果:失败
返回结果:
{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"Unexpected identifier"}
摘要
请求ID:4e47e746-1429-11e9-8070-525400770114
运行时间:2.581ms
计费时间:100ms
运行内存:0.125MB
日志
START RequestId: 4e47e746-1429-11e9-8070-525400770114
Event RequestId: 4e47e746-1429-11e9-8070-525400770114Event:{
"key1": "test value 1",
"key2": "test value 2",
"userInfo": {
"appId": "wx87c393a34109b2b2",
"openId": "oaoLb4qz0R8STBj6ipGlHkfNCO2Q"
}
}
END RequestId: 4e47e746-1429-11e9-8070-525400770114
Report RequestId: 4e47e746-1429-11e9-8070-525400770114 Duration:2.581ms Memory:256MB MaxMemoryUsed:0.125MB
- 复现路径
调用云函数时出错
- 提供代码片段
// 云函数入口文件
const cloud = require(
'wx-server-sdk'
)
cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
var
table_name = event.table_name
try
{
var
isExisted =
false
if
(table_name ==
"bookinfo"
) {
db.collection(table_name).where({
isbn: event.isbn
}).get({
success(res) {
if
(res.data.length == 0) {
return await
db.collection(table_name).add({
data: {
isbn: event.isbn,
title: event.title,
author: event.author
}
});
}
}
})
}
}
catch
(e) {
console.error(e)
}
}
// 云函数入口函数
exports.main = async (event, context) => {
var table_name = event.table_name
try {
var isExisted = false
if(table_name == "bookinfo") {
var res= await db.collection(table_name).where({
isbn: event.isbn
}).get()
if(res.data.length == 0) {
return await db.collection(table_name).add({
data: {
isbn: event.isbn,
title: event.title,
author: event.author
}
});
}
}
} catch (e) {
console.error(e)
}
}
好用,感谢感谢
服务端只支持Promise风格,不支持success回调
不知道这个要求,还以为跟小程序端一样呢;已解决,感谢感谢