@@ -54,18 +54,23 @@ async function getWindowsDefaultBrowserFromWsl() {
5454 return browserMap [ progId ] ? { id : browserMap [ progId ] } : { } ;
5555}
5656
57- const pTryEach = async ( array , mapper ) => {
58- let latestError ;
57+ const tryEachApp = async ( apps , opener ) => {
58+ if ( apps . length === 0 ) {
59+ // No app was provided
60+ return ;
61+ }
62+
63+ const errors = [ ] ;
5964
60- for ( const item of array ) {
65+ for ( const app of apps ) {
6166 try {
62- return await mapper ( item ) ; // eslint-disable-line no-await-in-loop
67+ return await opener ( app ) ; // eslint-disable-line no-await-in-loop
6368 } catch ( error ) {
64- latestError = error ;
69+ errors . push ( error ) ;
6570 }
6671 }
6772
68- throw latestError ;
73+ throw new AggregateError ( errors , 'Failed to open in all supported apps' ) ;
6974} ;
7075
7176// eslint-disable-next-line complexity
@@ -79,7 +84,7 @@ const baseOpen = async options => {
7984 } ;
8085
8186 if ( Array . isArray ( options . app ) ) {
82- return pTryEach ( options . app , singleApp => baseOpen ( {
87+ return tryEachApp ( options . app , singleApp => baseOpen ( {
8388 ...options ,
8489 app : singleApp ,
8590 } ) ) ;
@@ -89,7 +94,7 @@ const baseOpen = async options => {
8994 appArguments = [ ...appArguments ] ;
9095
9196 if ( Array . isArray ( app ) ) {
92- return pTryEach ( app , appName => baseOpen ( {
97+ return tryEachApp ( app , appName => baseOpen ( {
9398 ...options ,
9499 app : {
95100 name : appName ,
0 commit comments