Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda