[英]firebase function Unhandled error RangeError: Maximum call stack size exceeded
i have been stuck on this error for sometime and still cant figure out the source.我已经被这个错误困住了一段时间,但仍然无法弄清楚来源。 I am calling firebase function from client(javascript) but the firebase function side is throwing Maximum call stack error.
我正在从客户端(javascript)调用 firebase 函数,但 firebase 函数端抛出最大调用堆栈错误。 Here is my code
这是我的代码
exports.signInCart = functions.https.onCall(async (data, context) => {
console.log(data)
const sessionID = data.sessionID
console.log("session id ", sessionID)
const shopIntentRef = admin.database().ref('/shopIntent/'+ sessionID)
try{
shopIntentRef.once("value", (snapshot)=> {
if(!snapshot.val()){
console.log("not recognized ")
return "NA"
}
if(snapshot.val()){
admin.database().ref('/shopintent/'+ sessionID+'/').update(data);
return (snapshot.val());
}
});
}catch(ex){
console.log('ex /updateCoords = '+ex);
}
return shopIntentRef.once("value")
})
I tried couple of different things;我尝试了几种不同的方法; i thought i should be able to get some value without the last return statement and I did get a return status code 200 but no snapshot.val() was returned.
我想我应该能够在没有最后一个 return 语句的情况下获得一些值,我确实得到了一个返回状态代码 200 但没有返回 snapshot.val() 。 When I added the last return statement It started generating this error in firebase function console
当我添加最后一条 return 语句时,它开始在 firebase 函数控制台中生成此错误
Unhandled error RangeError: Maximum call stack size exceeded
at Object (<anonymous>)
at /workspace/node_modules/lodash/lodash.js:1198:19
at baseKeys (/workspace/node_modules/lodash/lodash.js:3484:16)
at keys (/workspace/node_modules/lodash/lodash.js:13333:60)
at /workspace/node_modules/lodash/lodash.js:4920:21
at baseForOwn (/workspace/node_modules/lodash/lodash.js:2990:24)
at Function.mapValues (/workspace/node_modules/lodash/lodash.js:13426:7)
at encode (/workspace/node_modules/firebase-functions/lib/providers/https.js:184:18)
at /workspace/node_modules/lodash/lodash.js:13427:38
at /workspace/node_modules/lodash/lodash.js:4925:15
5:41:07.909 PM下午 5:41:07.909
how do I resolve the above errors?如何解决上述错误?
You are trying to return a DataSnapshot object to the caller.您正在尝试将 DataSnapshot 对象返回给调用者。 Unfortunately, that object has circular references in it, and can't be serialized simply.
不幸的是,该对象中有循环引用,不能简单地序列化。 You will need to get a plain JavaScript object out of it and return that instead.
您需要从中获取一个普通的 JavaScript 对象并返回它。
return shopIntentRef.once("value").then(snapshot => {
return snapshot.val()
})
Also, you will need to take some time to correctly handle the promises earlier in your code, otherwise it might not work the way you expect.此外,您需要花一些时间在代码的早期正确处理承诺,否则它可能无法按您期望的方式工作。 Your code should only return a promise that resolves only after all the other async work is complete.
您的代码应该只返回一个只有在所有其他异步工作完成后才能解决的承诺。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.