Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
Firebase Functions - Does throwing errors produce cold starts?

I have read here that unhandled errors might cause cold starts. I am implementing a triggered function, as follows:

exports.detectPostLanguage = functions
  .region("us-central1")
  .runWith({ memory: "2GB", timeoutSeconds: "540" })
  .firestore.document("posts/{userId}/userPosts/{postId}")
  .onCreate(async (snap, context) => {
     // ...

     const language = await google.detectLanguage(post.text);

     // ... more stuff if no error with the async operation

  });

Do I need to catch the google.detectLanguage() method errors to avoid cold starts?

If yes, what should I do (A or B)?

A:

const language = await google.detectLanguage(post.text)
   .catch(err => {
       functions.logger.error(err);
       throw err; // <---- Will still cause the cold start?
   });

B:

try {
   var language = await google.detectLanguage(post.text)
} catch(err) {
   functions.logger.error(err);
   return null; // <----
}

UPDATE

Based on Frank solution:

exports.detectPostLanguage = functions
  .region("us-central1")
  .runWith({ memory: "2GB", timeoutSeconds: "540" })
  .firestore.document("posts/{userId}/userPosts/{postId}")
  .onCreate(async (snap, context) => {
     try {
        // ...

        const language = await google.detectLanguage(post.text);

        // ... more stuff if no error with the async operation
     } catch(err) {
        return Promise.reject(err);
     }
     
     return null; // or return Promise.resolve();
  });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If any exception escapes from the Cloud Function body, the runtime assumes that the container is left in an unstable state and won't schedule it to handle events anymore.

To prevent this, ensure that no exception escapes from your code. You can either return no value, or a promise that indicates when any asynchronous calls in your code are done.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!