@@ -398,6 +398,9 @@ abstract class ActivityPrinterBase implements IActivityPrinter {
398
398
399
399
protected readonly failures = new Array < StackActivity > ( ) ;
400
400
401
+
402
+ protected hookFailureMap = new Map < string , Map < string , string > > ( ) ;
403
+
401
404
protected readonly stream : NodeJS . WriteStream ;
402
405
403
406
constructor ( protected readonly props : PrinterProps ) {
@@ -411,8 +414,25 @@ abstract class ActivityPrinterBase implements IActivityPrinter {
411
414
this . stream = props . stream ;
412
415
}
413
416
417
+ public failureReason ( activity : StackActivity ) {
418
+ const resourceStatusReason = activity . event . ResourceStatusReason ?? '' ;
419
+ const logicalResourceId = activity . event . LogicalResourceId ?? '' ;
420
+ const hookFailureReasonMap = this . hookFailureMap . get ( logicalResourceId ) ;
421
+
422
+ if ( hookFailureReasonMap !== undefined ) {
423
+ for ( const hookType of hookFailureReasonMap . keys ( ) ) {
424
+ if ( resourceStatusReason . includes ( hookType ) ) {
425
+ return resourceStatusReason + ' : ' + hookFailureReasonMap . get ( hookType ) ;
426
+ }
427
+ }
428
+ }
429
+ return resourceStatusReason ;
430
+ }
431
+
414
432
public addActivity ( activity : StackActivity ) {
415
433
const status = activity . event . ResourceStatus ;
434
+ const hookStatus = activity . event . HookStatus ;
435
+ const hookType = activity . event . HookType ;
416
436
if ( ! status || ! activity . event . LogicalResourceId ) { return ; }
417
437
418
438
if ( status === 'ROLLBACK_IN_PROGRESS' || status === 'UPDATE_ROLLBACK_IN_PROGRESS' ) {
@@ -455,6 +475,16 @@ abstract class ActivityPrinterBase implements IActivityPrinter {
455
475
}
456
476
this . resourcesPrevCompleteState [ activity . event . LogicalResourceId ] = status ;
457
477
}
478
+
479
+ if ( hookStatus !== undefined && hookStatus . endsWith ( '_COMPLETE_FAILED' ) && activity . event . LogicalResourceId !== undefined && hookType !== undefined ) {
480
+
481
+ if ( this . hookFailureMap . has ( activity . event . LogicalResourceId ) ) {
482
+ this . hookFailureMap . get ( activity . event . LogicalResourceId ) ?. set ( hookType , activity . event . HookStatusReason ?? '' ) ;
483
+ } else {
484
+ this . hookFailureMap . set ( activity . event . LogicalResourceId , new Map < string , string > ( ) ) ;
485
+ this . hookFailureMap . get ( activity . event . LogicalResourceId ) ?. set ( hookType , activity . event . HookStatusReason ?? '' ) ;
486
+ }
487
+ }
458
488
}
459
489
460
490
public abstract print ( ) : void ;
@@ -529,8 +559,15 @@ export class HistoryActivityPrinter extends ActivityPrinterBase {
529
559
530
560
let stackTrace = '' ;
531
561
const md = activity . metadata ;
532
- if ( md && e . ResourceStatus && e . ResourceStatus . indexOf ( 'FAILED' ) !== - 1 ) {
533
- stackTrace = md . entry . trace ? `\n\t${ md . entry . trace . join ( '\n\t\\_ ' ) } ` : '' ;
562
+
563
+ if ( e . ResourceStatus && e . ResourceStatus . indexOf ( 'FAILED' ) !== - 1 ) {
564
+ if ( progress == undefined || progress ) {
565
+ e . ResourceStatusReason = e . ResourceStatusReason ? this . failureReason ( activity ) : '' ;
566
+ }
567
+ if ( md ) {
568
+ stackTrace = md . entry . trace ? `\n\t${ md . entry . trace . join ( '\n\t\\_ ' ) } ` : '' ;
569
+
570
+ }
534
571
reasonColor = chalk . red ;
535
572
}
536
573
@@ -703,7 +740,7 @@ export class CurrentActivityPrinter extends ActivityPrinterBase {
703
740
704
741
private failureReasonOnNextLine ( activity : StackActivity ) {
705
742
return hasErrorMessage ( activity . event . ResourceStatus ?? '' )
706
- ? `\n${ ' ' . repeat ( TIMESTAMP_WIDTH + STATUS_WIDTH + 6 ) } ${ chalk . red ( activity . event . ResourceStatusReason ?? '' ) } `
743
+ ? `\n${ ' ' . repeat ( TIMESTAMP_WIDTH + STATUS_WIDTH + 6 ) } ${ chalk . red ( this . failureReason ( activity ) ?? '' ) } `
707
744
: '' ;
708
745
}
709
746
}
@@ -718,6 +755,7 @@ function hasErrorMessage(status: string) {
718
755
return status . endsWith ( '_FAILED' ) || status === 'ROLLBACK_IN_PROGRESS' || status === 'UPDATE_ROLLBACK_IN_PROGRESS' ;
719
756
}
720
757
758
+
721
759
function colorFromStatusResult ( status ?: string ) {
722
760
if ( ! status ) {
723
761
return chalk . reset ;
@@ -767,3 +805,5 @@ function shorten(maxWidth: number, p: string) {
767
805
768
806
const TIMESTAMP_WIDTH = 12 ;
769
807
const STATUS_WIDTH = 20 ;
808
+
809
+
0 commit comments