簡體   English   中英

Firebase功能錯誤; “超出了最大調用堆棧大小”

[英]Firebase function error; “Maximum call stack size exceeded”

我已經創建了一個通過事務在數據庫中切換布爾值的函數。 看一看:

export const toggleDoneState = functions.https.onCall((data, context) => {
    const userId = getUserIdFromCallableContext(context)
    let togglePath: admin.database.Reference

    if (!isUndefined(data.subtaskId)) {
        const subtaskId = data.subtaskId
        if (isValidString(subtaskId)) {
            togglePath = admin.database().ref("userSubtasks").child(userId).child(subtaskId).child("done")
        } else {
            throw new functions.https.HttpsError('invalid-argument', 'Expected valid Subtask Id')
        }
    } else {
        throw new functions.https.HttpsError('invalid-argument', 'Expected valid toggle type')
    }

    return togglePath.transaction(currentValue => {
        return !(currentValue || false)
    }).then(value => { 
        return { done: value }
    })
})

這是我部署的唯一功能! 我過去大約有15個函數在運行,但為了使此測試更加簡潔,我已經刪除了它們。

當我從iOS應用程序調用函數時,我看到數據庫中的值已按預期進行切換,但是從iOS中的Functions SDK收到錯誤消息:

Domain=com.firebase.functions Code=13 "INTERNAL" UserInfo={NSLocalizedDescription=INTERNAL}

當我在控制台中查看功能日志時,看到以下錯誤:

未處理的錯誤RangeError:超出最大調用堆棧大小

 at Function.mapValues (/user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:13395:23) at encode (/user_code/node_modules/firebase-functions/lib/providers/https.js:204:18) 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:204:18) 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) 

數據庫中的值已按預期切換,但我不想獲取並出錯並理解原因。 有什么線索嗎?

我懷疑你有什么誤會value是在then的交易后回調。 如果查看transaction()的API文檔,您會看到它返回一個包含幾個屬性的Promise,其中之一是DataSnapshot。 您實際上是在嘗試序列化該DataSnapshot對象,並且我認為lodash遇到了問題,也許是循環引用。

首先,嘗試修復您的then回調的返回值,看看是否可以解決問題。 然后,弄清楚如何使用事務產生的DataSnapshot將所需的值返回給客戶端。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM