3
votes

Likely an easy question for somebody in the know...

I was reading the documentation for Firebase Cloud Functions and GCP Cloud Functions and I noticed that there is a difference in the recommended approach for handling errors. This surprised me because my understanding is that Firebase Cloud Functions are very closely related to GCP Cloud Functions.

In the Firebase documentation on error reporting it indicates that an error may be thrown to get it into StackDriver, as follows:

throw new Error('Fail!');

Meanwhile, the GCP Cloud Function documentation on error reporting states that uncaught exceptions force a cold start on a future invocation. Instead, the following is suggested:

console.error(new Error('Fail!'));

Does throwing the Error directly also cause a cold start on Firebase Cloud Functions? On Firebase, does sending the error to the console avoid this problem?

Thanks.

1

1 Answers

6
votes

The documentation for Cloud is correct. At this moment, the Firebase docs need to be updated to match the changes that were made for Cloud.

An instance will be restarted after a function throws 3 exceptions. It's likely in your best interest to catch after every then chain, and log the error with console.error().