@@ -399,29 +399,48 @@ export const Core = {
399
399
app : FabrixApp ,
400
400
spools : Spool [ ]
401
401
) {
402
+ // TODO, eliminate waiting on lifecycle events that will not exist
403
+ // https://github.com/fabrix-app/fabrix/issues/14
402
404
const validatedEvents = spools . map ( spool => `spool:${ spool . name } :validated` )
403
405
const configuredEvents = spools . map ( spool => `spool:${ spool . name } :configured` )
404
406
const initializedEvents = spools . map ( spool => `spool:${ spool . name } :initialized` )
405
407
const sanityEvents = spools . map ( spool => `spool:${ spool . name } :sane` )
406
408
407
- app . after ( configuredEvents ) . then ( async ( ) => {
408
- await this . createDefaultPaths ( app )
409
- app . emit ( 'spool:all:configured' )
410
- } )
409
+ app . after ( configuredEvents )
410
+ . then ( async ( ) => {
411
+ await this . createDefaultPaths ( app )
412
+ app . emit ( 'spool:all:configured' )
413
+ } )
414
+ . catch ( err => {
415
+ app . log . error ( err )
416
+ throw err
417
+ } )
411
418
412
419
app . after ( validatedEvents )
413
420
. then ( ( ) => app . emit ( 'spool:all:validated' ) )
421
+ . catch ( err => {
422
+ app . log . error ( err )
423
+ throw err
424
+ } )
414
425
415
426
app . after ( initializedEvents )
416
427
. then ( ( ) => {
417
428
app . emit ( 'spool:all:initialized' )
418
429
} )
430
+ . catch ( err => {
431
+ app . log . error ( err )
432
+ throw err
433
+ } )
419
434
420
435
app . after ( sanityEvents )
421
436
. then ( ( ) => {
422
437
app . emit ( 'spool:all:sane' )
423
438
app . emit ( 'fabrix:ready' )
424
439
} )
440
+ . catch ( err => {
441
+ app . log . error ( err )
442
+ throw err
443
+ } )
425
444
} ,
426
445
427
446
/**
@@ -440,39 +459,41 @@ export const Core = {
440
459
. then ( ( ) => spool . sanity ( ) )
441
460
. then ( ( ) => app . emit ( `spool:${ spool . name } :sane` ) )
442
461
. then ( ( ) => spool . stage = 'sane' )
443
- . catch ( this . handlePromiseRejection )
462
+ . catch ( err => this . handlePromiseRejection ( app , err ) )
444
463
445
464
app . after ( ( lifecycle . initialize . listen ) . concat ( 'spool:all:configured' ) )
446
465
. then ( ( ) => app . log . debug ( 'spool: initializing' , spool . name ) )
447
466
. then ( ( ) => spool . stage = 'initializing' )
448
467
. then ( ( ) => spool . initialize ( ) )
449
468
. then ( ( ) => app . emit ( `spool:${ spool . name } :initialized` ) )
450
469
. then ( ( ) => spool . stage = 'initialized' )
451
- . catch ( this . handlePromiseRejection )
470
+ . catch ( err => this . handlePromiseRejection ( app , err ) )
452
471
453
472
app . after ( ( lifecycle . configure . listen ) . concat ( 'spool:all:validated' ) )
454
473
. then ( ( ) => app . log . debug ( 'spool: configuring' , spool . name ) )
455
474
. then ( ( ) => spool . stage = 'configuring' )
456
475
. then ( ( ) => spool . configure ( ) )
457
476
. then ( ( ) => app . emit ( `spool:${ spool . name } :configured` ) )
458
477
. then ( ( ) => spool . stage = 'configured' )
459
- . catch ( this . handlePromiseRejection )
478
+ . catch ( err => this . handlePromiseRejection ( app , err ) )
460
479
461
480
app . after ( 'fabrix:start' )
462
481
. then ( ( ) => app . log . debug ( 'spool: validating' , spool . name ) )
463
482
. then ( ( ) => spool . stage = 'validating' )
464
483
. then ( ( ) => spool . validate ( ) )
465
484
. then ( ( ) => app . emit ( `spool:${ spool . name } :validated` ) )
466
485
. then ( ( ) => spool . stage = 'validated' )
467
- . catch ( this . handlePromiseRejection )
486
+ . catch ( err => this . handlePromiseRejection ( app , err ) )
468
487
} ,
469
488
470
489
/**
471
490
* Handle a promise rejection
472
491
*/
473
- handlePromiseRejection ( err : Error ) : void {
474
- console . error ( err )
492
+ handlePromiseRejection ( app : FabrixApp , err : Error ) : void {
493
+ app . log . error ( err )
475
494
throw err
495
+
496
+ return
476
497
}
477
498
478
499
}
0 commit comments