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

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

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 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