I'm not sure this fits nicely into things. The issue is that `Promise.all` rejects as soon as it gets _any_ errors, so your `catch` block will run before there are multiple errors. The syntax used around `Promise.all` should not influence the behavior of `Promise.all` itself, so the only way to do what you want would be to manually use `Promise.allSettled` or something along those lines, and that would already provide the ability to throw a singular array of errors, which would avoid the need for `...errors` in the first place.
On Tue, Jul 14, 2020 at 11:29 PM Michaël Rouges <[email protected]> wrote: > Hi all, > > My proposal's goal is really simple: provide a way to handle any numbers > of errors, at once, in a synced try... catch. > > The problem: > ------------------ > ` > async function reject (key) { > throw new Error(`error with key: ${key}`) > } > > async function test () { > try { > await Promise.all([...new Array(3).keys()].map(reject)) > } catch (error) { > console.error(error) // Error: error with key: 0 > } > } > > test() > ` > > Actually, we don't have a simple way to retrieve all errors in the catch > and it can be difficult to manage when we don't know how many errors we can > receive. > > Then, IMHO, allowing the rest parameter on the `catch (...errors)` > resolves that problem, without breaking changes. > > What do you think about it, please? > > > Cordially, > Michaël Rouges - https://github.com/Lcfvs - @Lcfvs > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

