首页 > 解决方案 > Firebase 云函数 - 未处理的错误 RangeError

问题描述

这是我部署的唯一功能:

exports.gameAction = functions.https.onCall((data, context) => { 
    const timeoutRef = admin.database().ref('/current_player/timeout');
    return timeoutRef.transaction((timeout) => {
        return;
    });
});

如果我理解正确,事务将在调用后立即中止,但是当我从我的应用程序调用此函数时,控制台会显示以下错误:

Unhandled error RangeError: Maximum call stack size exceeded
    at Object (native)
    at baseGetTag (/user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:3087:51)
    at Function.isBoolean (/user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:11383:33)
    at encode (/user_code/node_modules/firebase-functions/lib/providers/https.js:229:11)
    at /user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:13400:38
    at /user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:4925:15
    at baseForOwn (/user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:3010:24)
    at Function.mapValues (/user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:13399:7)
    at encode (/user_code/node_modules/firebase-functions/lib/providers/https.js:242:18)
    at /user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:13400:38

我在这里想念什么?

标签: firebasefirebase-realtime-databasegoogle-cloud-functions

解决方案


onCall 函数将数据发送回客户端的方式是返回一个承诺,该承诺与要发送的对象数据一起解析。因此,Cloud Functions 尝试将事务返回的 Promise 中包含的数据序列化,然后以 JSON 格式发送给客户端。

正如您从transaction()的 API 文档中看到的那样,promise 包含一个 Reference 对象,其中包含有关该引用的各种元数据。它可能包含一个循环数据结构,而 Cloud Functions 一直在尝试序列化无限循环。

试着从你的函数中返回一些不太复杂的东西。


推荐阅读