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

473
Visualizações
Inspecting Errors after calling Promise.allSettled

In my code I'm trying to dispatch jobs (FoundryVTT data object migrations) in parallel, and capture any errors on the way.

After they have all run their course, I'm trying to print the error details together. The problem is the errors for an individual actor are not "caught", but I can see the rejected promises at the end. Here's my code:

const actorMigrations = await game.actors.contents.map((actor) => {
  try {
    return this.updateActor(actor);
  } catch (err) {
    throw new Error(`${actor.name} had a migration error: ${err.message}`);    
  }
});
const values = await Promise.allSettled(actorMigrations);
for (const value of values.filter((v) => v.status !== "fulfilled")) {
  LOGGER.error(`Migration error: ${value.reason.message}`);
  LOGGER.error(value.reason.stack);
  return false;
} 

What's the right pattern I should be following here?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I suppose you're looking for

const actorMigrations =   game.actors.contents.map((actor) => {
//                      ^
  try {
    return await this.updateActor(actor);
//         ^^^^^
  } catch (err) {
    throw new Error(`${actor.name} had a migration error: ${err.message}`);    
  }
});

You don't need to await the array that map() returns (it won't do anything - you can only await the promise that Promise.allSettled() returns), and you'll want to await the promise that updateActor() returns so that rejections will be caught by the try/catch block.

about 4 years ago · Santiago Trujillo 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