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

471
Views
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 answers
Answer question

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