忽略 Google 云控制台测试中已完成函数的异常

Ignoring exception from a finished function in Google Cloud Console Test

我正在尝试通过电子邮件向自己发送我的 firebase 数据库的 OnCreate。我在 google 云函数中测试时收到错误 "Ignoring exception from a finished function"。

const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
const gmailEmail = functions.config().gmail.email;
const gmailPassword = functions.config().gmail.password;
const mailTransport = nodemailer.createTransport({
 service: 'gmail',
 auth: {
   user: gmailEmail,
   pass: gmailPassword,
  },
});

const APP_NAME = 'Your App';
exports.sendWelcomeEmail = functions.database.ref('/PickupRequests{pushID}').onCreate((snapshot, context) => {
  return sendWelcomeEmail();
});

async function sendWelcomeEmail() {
  const mailOptions = {
    from: "<noreply@firebase.com>",
    to: "info@abc.com",
    subject: "New Request"
  };
  await mailTransport.sendMail(mailOptions);
  return console.log("Success!");
}

我希望收到一封电子邮件,但我收到了来自 Google 云测试仪的错误,该错误指出 "Ignoring exception from a finished function",尽管控制台也在返回 "Success!"。这是完整的错误:

 "textPayload": "Ignoring exception from a finished function",
  "insertId": "000000-5e081b31-9b2f-4f9a-a6a6-6c7ca4d38814",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "project_id": "your-app",
      "region": "us-central1",
      "function_name": "sendWelcomeEmail"
    }
  },
  "timestamp": "2019-05-31T00:56:56.926Z",
  "severity": "DEBUG",
  "labels": {
    "execution_id": "jbvvfsrrf8yz"
  },
  "logName": "projects/your-app/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
  "trace": "projects/your-app/traces/5af3a317b80ee34154c1caf1536fc16e",
  "receiveTimestamp": "2019-05-31T00:57:02.981796854Z"
}

我能够通过以下代码解决此问题:

'use strict';

const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
const username = functions.config().gmail.email;
const password = functions.config().gmail.password;
const mailTransport = nodemailer.createTransport({
 service: 'gmail',
 auth: {
   user: gmailEmail,
   pass: gmailPassword,
  },
});
exports.sendPickupRequest = functions.database.ref('/PickupRequests/{pushId}').onCreate(async(snapshot, context) => {

  const val = snapshot.val();
  const final = JSON.stringify(val)
  const mailOptions = {
    from: gmailEmail,
    to: "info@abc.com",
    subject: "New Request"
  };
  try {
    await mailTransport.sendMail(mailOptions);
    console.log('email sent');
  } catch(error) {
    console.error('There was an error while sending the email:', error);
  }
  return null;
});