@@ -140,14 +140,14 @@ export class CfnInclude extends core.CfnElement {
140
140
141
141
for ( const logicalId of this . dehydratedResources ) {
142
142
if ( ! Object . keys ( this . template . Resources ) . includes ( logicalId ) ) {
143
- throw new Error ( `Logical ID '${ logicalId } ' was specified in 'dehydratedResources', but does not belong to a resource in the template.` ) ;
143
+ throw new core . ValidationError ( `Logical ID '${ logicalId } ' was specified in 'dehydratedResources', but does not belong to a resource in the template.` , this ) ;
144
144
}
145
145
}
146
146
147
147
// check if all user specified parameter values exist in the template
148
148
for ( const logicalId of Object . keys ( this . parametersToReplace ) ) {
149
149
if ( ! ( logicalId in ( this . template . Parameters || { } ) ) ) {
150
- throw new Error ( `Parameter with logical ID '${ logicalId } ' was not found in the template` ) ;
150
+ throw new core . ValidationError ( `Parameter with logical ID '${ logicalId } ' was not found in the template` , this ) ;
151
151
}
152
152
}
153
153
@@ -182,7 +182,7 @@ export class CfnInclude extends core.CfnElement {
182
182
// verify that all nestedStacks have been instantiated
183
183
for ( const nestedStackId of Object . keys ( props . loadNestedStacks || { } ) ) {
184
184
if ( ! ( nestedStackId in this . resources ) ) {
185
- throw new Error ( `Nested Stack with logical ID '${ nestedStackId } ' was not found in the template` ) ;
185
+ throw new core . ValidationError ( `Nested Stack with logical ID '${ nestedStackId } ' was not found in the template` , this ) ;
186
186
}
187
187
}
188
188
@@ -217,7 +217,7 @@ export class CfnInclude extends core.CfnElement {
217
217
public getResource ( logicalId : string ) : core . CfnResource {
218
218
const ret = this . resources [ logicalId ] ;
219
219
if ( ! ret ) {
220
- throw new Error ( `Resource with logical ID '${ logicalId } ' was not found in the template` ) ;
220
+ throw new core . ValidationError ( `Resource with logical ID '${ logicalId } ' was not found in the template` , this ) ;
221
221
}
222
222
return ret ;
223
223
}
@@ -235,7 +235,7 @@ export class CfnInclude extends core.CfnElement {
235
235
public getCondition ( conditionName : string ) : core . CfnCondition {
236
236
const ret = this . conditions [ conditionName ] ;
237
237
if ( ! ret ) {
238
- throw new Error ( `Condition with name '${ conditionName } ' was not found in the template` ) ;
238
+ throw new core . ValidationError ( `Condition with name '${ conditionName } ' was not found in the template` , this ) ;
239
239
}
240
240
return ret ;
241
241
}
@@ -253,7 +253,7 @@ export class CfnInclude extends core.CfnElement {
253
253
public getParameter ( parameterName : string ) : core . CfnParameter {
254
254
const ret = this . parameters [ parameterName ] ;
255
255
if ( ! ret ) {
256
- throw new Error ( `Parameter with name '${ parameterName } ' was not found in the template` ) ;
256
+ throw new core . ValidationError ( `Parameter with name '${ parameterName } ' was not found in the template` , this ) ;
257
257
}
258
258
return ret ;
259
259
}
@@ -270,7 +270,7 @@ export class CfnInclude extends core.CfnElement {
270
270
public getMapping ( mappingName : string ) : core . CfnMapping {
271
271
const ret = this . mappings [ mappingName ] ;
272
272
if ( ! ret ) {
273
- throw new Error ( `Mapping with name '${ mappingName } ' was not found in the template` ) ;
273
+ throw new core . ValidationError ( `Mapping with name '${ mappingName } ' was not found in the template` , this ) ;
274
274
}
275
275
return ret ;
276
276
}
@@ -288,7 +288,7 @@ export class CfnInclude extends core.CfnElement {
288
288
public getOutput ( logicalId : string ) : core . CfnOutput {
289
289
const ret = this . outputs [ logicalId ] ;
290
290
if ( ! ret ) {
291
- throw new Error ( `Output with logical ID '${ logicalId } ' was not found in the template` ) ;
291
+ throw new core . ValidationError ( `Output with logical ID '${ logicalId } ' was not found in the template` , this ) ;
292
292
}
293
293
return ret ;
294
294
}
@@ -306,7 +306,7 @@ export class CfnInclude extends core.CfnElement {
306
306
public getRule ( ruleName : string ) : core . CfnRule {
307
307
const ret = this . rules [ ruleName ] ;
308
308
if ( ! ret ) {
309
- throw new Error ( `Rule with name '${ ruleName } ' was not found in the template` ) ;
309
+ throw new core . ValidationError ( `Rule with name '${ ruleName } ' was not found in the template` , this ) ;
310
310
}
311
311
return ret ;
312
312
}
@@ -324,7 +324,7 @@ export class CfnInclude extends core.CfnElement {
324
324
public getHook ( hookLogicalId : string ) : core . CfnHook {
325
325
const ret = this . hooks [ hookLogicalId ] ;
326
326
if ( ! ret ) {
327
- throw new Error ( `Hook with logical ID '${ hookLogicalId } ' was not found in the template` ) ;
327
+ throw new core . ValidationError ( `Hook with logical ID '${ hookLogicalId } ' was not found in the template` , this ) ;
328
328
}
329
329
return ret ;
330
330
}
@@ -340,12 +340,12 @@ export class CfnInclude extends core.CfnElement {
340
340
public getNestedStack ( logicalId : string ) : IncludedNestedStack {
341
341
if ( ! this . nestedStacks [ logicalId ] ) {
342
342
if ( ! this . template . Resources [ logicalId ] ) {
343
- throw new Error ( `Nested Stack with logical ID '${ logicalId } ' was not found in the template` ) ;
343
+ throw new core . ValidationError ( `Nested Stack with logical ID '${ logicalId } ' was not found in the template` , this ) ;
344
344
} else if ( this . template . Resources [ logicalId ] . Type !== 'AWS::CloudFormation::Stack' ) {
345
- throw new Error ( `Resource with logical ID '${ logicalId } ' is not a CloudFormation Stack` ) ;
345
+ throw new core . ValidationError ( `Resource with logical ID '${ logicalId } ' is not a CloudFormation Stack` , this ) ;
346
346
} else {
347
- throw new Error ( `Nested Stack '${ logicalId } ' was not included in the parent template. ` +
348
- 'To retrieve an included nested stack, it must be specified either in the `loadNestedStacks` property, or through the `loadNestedStack` method' ) ;
347
+ throw new core . ValidationError ( `Nested Stack '${ logicalId } ' was not included in the parent template. ` +
348
+ 'To retrieve an included nested stack, it must be specified either in the `loadNestedStacks` property, or through the `loadNestedStack` method' , this ) ;
349
349
}
350
350
}
351
351
return this . nestedStacks [ logicalId ] ;
@@ -364,11 +364,11 @@ export class CfnInclude extends core.CfnElement {
364
364
*/
365
365
public loadNestedStack ( logicalId : string , nestedStackProps : CfnIncludeProps ) : IncludedNestedStack {
366
366
if ( logicalId in this . nestedStacks ) {
367
- throw new Error ( `Nested Stack '${ logicalId } ' was already included in its parent template` ) ;
367
+ throw new core . ValidationError ( `Nested Stack '${ logicalId } ' was already included in its parent template` , this ) ;
368
368
}
369
369
const cfnStack = this . resources [ logicalId ] ;
370
370
if ( ! cfnStack ) {
371
- throw new Error ( `Nested Stack with logical ID '${ logicalId } ' was not found in the template` ) ;
371
+ throw new core . ValidationError ( `Nested Stack with logical ID '${ logicalId } ' was not found in the template` , this ) ;
372
372
}
373
373
if ( cfnStack instanceof core . CfnStack ) {
374
374
// delete the old CfnStack child - one will be created by the NestedStack object
@@ -381,7 +381,7 @@ export class CfnInclude extends core.CfnElement {
381
381
this . getOrCreateResource ( logicalId ) ;
382
382
return this . nestedStacks [ logicalId ] ;
383
383
} else {
384
- throw new Error ( `Nested Stack with logical ID '${ logicalId } ' is not an AWS::CloudFormation::Stack resource` ) ;
384
+ throw new core . ValidationError ( `Nested Stack with logical ID '${ logicalId } ' is not an AWS::CloudFormation::Stack resource` , this ) ;
385
385
}
386
386
}
387
387
@@ -429,12 +429,13 @@ export class CfnInclude extends core.CfnElement {
429
429
}
430
430
431
431
private createMapping ( mappingName : string ) : void {
432
+ const self = this ;
432
433
const cfnParser = new cfn_parse . CfnParser ( {
433
434
finder : {
434
- findCondition ( ) { throw new Error ( 'Referring to Conditions in Mapping definitions is not allowed' ) ; } ,
435
- findMapping ( ) { throw new Error ( 'Referring to other Mappings in Mapping definitions is not allowed' ) ; } ,
436
- findRefTarget ( ) { throw new Error ( 'Using Ref expressions in Mapping definitions is not allowed' ) ; } ,
437
- findResource ( ) { throw new Error ( 'Using GetAtt expressions in Mapping definitions is not allowed' ) ; } ,
435
+ findCondition ( ) { throw new core . ValidationError ( 'Referring to Conditions in Mapping definitions is not allowed' , self ) ; } ,
436
+ findMapping ( ) { throw new core . ValidationError ( 'Referring to other Mappings in Mapping definitions is not allowed' , self ) ; } ,
437
+ findRefTarget ( ) { throw new core . ValidationError ( 'Using Ref expressions in Mapping definitions is not allowed' , self ) ; } ,
438
+ findResource ( ) { throw new core . ValidationError ( 'Using GetAtt expressions in Mapping definitions is not allowed' , self ) ; } ,
438
439
} ,
439
440
parameters : { } ,
440
441
} ) ;
@@ -450,12 +451,13 @@ export class CfnInclude extends core.CfnElement {
450
451
return ;
451
452
}
452
453
454
+ const self = this ;
453
455
const expression = new cfn_parse . CfnParser ( {
454
456
finder : {
455
- findResource ( ) { throw new Error ( 'Using GetAtt expressions in Parameter definitions is not allowed' ) ; } ,
456
- findRefTarget ( ) { throw new Error ( 'Using Ref expressions in Parameter definitions is not allowed' ) ; } ,
457
- findCondition ( ) { throw new Error ( 'Referring to Conditions in Parameter definitions is not allowed' ) ; } ,
458
- findMapping ( ) { throw new Error ( 'Referring to Mappings in Parameter definitions is not allowed' ) ; } ,
457
+ findResource ( ) { throw new core . ValidationError ( 'Using GetAtt expressions in Parameter definitions is not allowed' , self ) ; } ,
458
+ findRefTarget ( ) { throw new core . ValidationError ( 'Using Ref expressions in Parameter definitions is not allowed' , self ) ; } ,
459
+ findCondition ( ) { throw new core . ValidationError ( 'Referring to Conditions in Parameter definitions is not allowed' , self ) ; } ,
460
+ findMapping ( ) { throw new core . ValidationError ( 'Referring to Mappings in Parameter definitions is not allowed' , self ) ; } ,
459
461
} ,
460
462
parameters : { } ,
461
463
} ) . parseValue ( this . template . Parameters [ logicalId ] ) ;
@@ -485,7 +487,7 @@ export class CfnInclude extends core.CfnElement {
485
487
// only parameters can be referenced in Rules
486
488
return self . parameters [ refTarget ] ;
487
489
} ,
488
- findResource ( ) { throw new Error ( 'Using GetAtt expressions in Rule definitions is not allowed' ) ; } ,
490
+ findResource ( ) { throw new core . ValidationError ( 'Using GetAtt expressions in Rule definitions is not allowed' , self ) ; } ,
489
491
findCondition ( conditionName : string ) : core . CfnCondition | undefined {
490
492
return self . conditions [ conditionName ] ;
491
493
} ,
@@ -575,8 +577,8 @@ export class CfnInclude extends core.CfnElement {
575
577
return self . getCondition ( outputAttributes . Condition ) ;
576
578
}
577
579
578
- throw new Error ( `Output with name '${ logicalId } ' refers to a Condition with name ` +
579
- `'${ outputAttributes . Condition } ' which was not found in this template` ) ;
580
+ throw new core . ValidationError ( `Output with name '${ logicalId } ' refers to a Condition with name ` +
581
+ `'${ outputAttributes . Condition } ' which was not found in this template` , this ) ;
580
582
} ) ( ) ,
581
583
} ) ;
582
584
@@ -592,7 +594,7 @@ export class CfnInclude extends core.CfnElement {
592
594
const self = this ;
593
595
const cfnParser = new cfn_parse . CfnParser ( {
594
596
finder : {
595
- findResource ( ) { throw new Error ( 'Using GetAtt in Condition definitions is not allowed' ) ; } ,
597
+ findResource ( ) { throw new core . ValidationError ( 'Using GetAtt in Condition definitions is not allowed' , self ) ; } ,
596
598
findRefTarget ( elementName : string ) : core . CfnElement | undefined {
597
599
// only Parameters can be referenced in the 'Conditions' section
598
600
return self . parameters [ elementName ] ;
@@ -626,7 +628,7 @@ export class CfnInclude extends core.CfnElement {
626
628
cycleChain = cycleChain . concat ( [ logicalId ] ) ;
627
629
if ( cycleChain . length !== new Set ( cycleChain ) . size ) {
628
630
if ( ! this . allowCyclicalReferences ) {
629
- throw new Error ( `Found a cycle between resources in the template: ${ cycleChain . join ( ' depends on ' ) } ` ) ;
631
+ throw new core . ValidationError ( `Found a cycle between resources in the template: ${ cycleChain . join ( ' depends on ' ) } ` , this ) ;
630
632
}
631
633
// only allow one placeholder per logical id
632
634
if ( this . logicalIdToPlaceholderMap . get ( logicalId ) ) {
@@ -683,7 +685,7 @@ export class CfnInclude extends core.CfnElement {
683
685
const resourceAttributes : any = this . template . Resources [ logicalId ] ;
684
686
let l1Instance : core . CfnResource ;
685
687
if ( this . nestedStacksToInclude [ logicalId ] && this . dehydratedResources . includes ( logicalId ) ) {
686
- throw new Error ( `nested stack '${ logicalId } ' was marked as dehydrated - nested stacks cannot be dehydrated` ) ;
688
+ throw new core . ValidationError ( `nested stack '${ logicalId } ' was marked as dehydrated - nested stacks cannot be dehydrated` , this ) ;
687
689
} else if ( this . nestedStacksToInclude [ logicalId ] ) {
688
690
l1Instance = this . createNestedStack ( logicalId , cfnParser ) ;
689
691
} else if ( this . dehydratedResources . includes ( logicalId ) ) {
@@ -758,13 +760,13 @@ export class CfnInclude extends core.CfnElement {
758
760
const nestedStackAttributes = templateResources [ nestedStackId ] || { } ;
759
761
760
762
if ( nestedStackAttributes . Type !== 'AWS::CloudFormation::Stack' ) {
761
- throw new Error ( `Nested Stack with logical ID '${ nestedStackId } ' is not an AWS::CloudFormation::Stack resource` ) ;
763
+ throw new core . ValidationError ( `Nested Stack with logical ID '${ nestedStackId } ' is not an AWS::CloudFormation::Stack resource` , this ) ;
762
764
}
763
765
if ( nestedStackAttributes . CreationPolicy ) {
764
- throw new Error ( 'CreationPolicy is not supported by the AWS::CloudFormation::Stack resource' ) ;
766
+ throw new core . ValidationError ( 'CreationPolicy is not supported by the AWS::CloudFormation::Stack resource' , this ) ;
765
767
}
766
768
if ( nestedStackAttributes . UpdatePolicy ) {
767
- throw new Error ( 'UpdatePolicy is not supported by the AWS::CloudFormation::Stack resource' ) ;
769
+ throw new core . ValidationError ( 'UpdatePolicy is not supported by the AWS::CloudFormation::Stack resource' , this ) ;
768
770
}
769
771
770
772
const nestedStackProps = cfnParser . parseValue ( nestedStackAttributes . Properties ) ;
0 commit comments