SYSTEM_ERROR:系统遇到意外错误。功能被杀死。云功能

时间:2017-08-21 03:53:52

标签: node.js firebase google-cloud-functions

当我查看来自Firebase云功能的日志时,我注意到某些功能在日志中有错误,描述为“SYSTEM_ERROR:系统遇到意外错误。功能被杀。”,直到昨天,这种行为不是,这里是其中一个功能。我该如何解决?

const functions = require('firebase-functions');
const admin = require('firebase-admin');

module.exports = functions.database.ref('/cards/{cardID}/interestedUsers').onWrite(event => {
    const cardID = event.params.cardID;

    console.log("interestedUsers", event.data.val(), cardID);

    var currentInterestedUsers = [];
    currentInterestedUsers = event.data.val();
    var previousInterestedUsers = [];
    previousInterestedUsers = event.data.previous.val();

    if (event.data.previous.val() && currentInterestedUsers) {
        var isNewPendingRequest = false;
        if (currentInterestedUsers.length < previousInterestedUsers.length) {
            currentInterestedUsers.forEach((interestedUser, index) => {
                const interestedUserVal = interestedUser.val();
                const isApproved = interestedUser["isApproved"];
                console.log("result", interestedUser.val(), interestedUserVal);
                if (isApproved == false) {
                    isNewPendingRequest = true;
                }
            });
        }

        if (isNewPendingRequest == false) {
            const cardRef = admin.database().ref("cards").child(cardID);
            const setupIsNewPendingRequestPromise = cardRef.update({
                "isNewPendingRequest": false
            });
            return Promise.all([setupIsNewPendingRequestPromise]);
        };

        return console.log("interestedUsers deleting");
    };

    if (event.data.val() == null) {
        console.log("event.data.val() == null");
        const cardRef = admin.database().ref("cards").child(cardID);
        // check card
        const cardCheckPromise = cardRef.once("value", function(cardCheckPromiseSnap, error){
            if (error) {
                return console.log("cardCheckPromise", error);
            };

            if (cardCheckPromiseSnap.val()) {
                const checkCardID = cardCheckPromiseSnap.val()["id"];
                if (checkCardID)  {
                    console.log("checkCardID", checkCardID);
                    const setupIsNewPendingRequestPromise = cardRef.update({
                        "isNewPendingRequest": false
                    });
                    return Promise.all([setupIsNewPendingRequestPromise]);
                } else {
                    return console.log("checkCardID == null");
                }
            } else {
                return console.log("cardCheckPromiseSnap.val() == null");
            };
        });
        return Promise.all([cardCheckPromise]).catch(function(cardCheckPromiseError){
            console.log("cardCheckPromise error", cardCheckPromiseError.message, cardCheckPromiseError.messageId)
        });
    }


    return console.log("just update or adding a new interested user");
});

2 个答案:

答案 0 :(得分:1)

您可以尝试重新部署您的应用。

答案 1 :(得分:0)

可能是GCF中断。有一个todayyesterday。在停电期间抛出了这些错误。

<强>解决方案 休息一下,等待云愈合。如果您购买了支持,请联系GCP支持。