首页 > 解决方案 > Cloud Function 失败并显示消息“错误:函数在请求范围外崩溃”

问题描述

我无法让最简单的 Firebase Cloud Function 正确执行。下面的代码不会产生任何控制台日志记录,除了错误: Error: function crashed out of request scopeFunction invocation was interrupted.

exports.testFunction = functions.firestore.document('trigger/dummy2').onUpdate(async (change : any, context : any) => {
    console.log( "How can this fail?" );
});

标签: firebasegoogle-cloud-functions

解决方案


这在文档中并不明显(至少对我而言),但async函数需要返回一个 Promise。如果这是不相关的要求,您可以返回已解决的承诺。

exports.testFunction = functions.firestore.document('trigger/dummy2').onUpdate(async (change : any, context : any) => {
    console.log( "How can this fail?" );
    return Promise.resolve(100);
});

推荐阅读