11import type { IConstruct } from 'constructs' ;
2- import { UnscopedValidationError , ValidationError } from 'aws-cdk-lib/core' ;
2+ import { ValidationError } from 'aws-cdk-lib/core' ;
33import type { IMixin } from './mixins' ;
44import { ConstructSelector } from './selectors' ;
55
@@ -25,11 +25,11 @@ export class MixinApplicator {
2525 const constructs = this . selector . select ( this . scope ) ;
2626 for ( const construct of constructs ) {
2727 if ( mixin . supports ( construct ) ) {
28- mixin . applyTo ( construct ) ;
2928 const errors = mixin . validate ?.( construct ) ?? [ ] ;
3029 if ( errors . length > 0 ) {
31- throw new ValidationError ( `Mixin validation failed: ${ errors . join ( ', ' ) } ` , construct ) ;
30+ throw new ValidationError ( `Mixin validation failed: ${ errors . join ( ', ' ) } ` , this . scope ) ;
3231 }
32+ mixin . applyTo ( construct ) ;
3333 }
3434 }
3535 return this ;
@@ -43,16 +43,16 @@ export class MixinApplicator {
4343 let applied = false ;
4444 for ( const construct of constructs ) {
4545 if ( mixin . supports ( construct ) ) {
46- mixin . applyTo ( construct ) ;
4746 const errors = mixin . validate ?.( construct ) ?? [ ] ;
4847 if ( errors . length > 0 ) {
4948 throw new ValidationError ( `Mixin validation failed: ${ errors . join ( ', ' ) } ` , construct ) ;
5049 }
50+ mixin . applyTo ( construct ) ;
5151 applied = true ;
5252 }
5353 }
5454 if ( ! applied ) {
55- throw new UnscopedValidationError ( `Mixin ${ mixin . constructor . name } could not be applied to any constructs` ) ;
55+ throw new ValidationError ( `Mixin ${ mixin . constructor . name } could not be applied to any constructs` , this . scope ) ;
5656 }
5757 return this ;
5858 }
0 commit comments