Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda