@@ -10,6 +10,7 @@ import { findParameters, hasParameter } from './private/parameters';
10
10
import { allResources , allResourcesProperties , countResources , countResourcesProperties , findResources , hasResource , hasResourceProperties } from './private/resources' ;
11
11
import { Template as TemplateType } from './private/template' ;
12
12
import { Stack , Stage } from '../../core' ;
13
+ import { AssertionError } from './private/error' ;
13
14
14
15
/**
15
16
* Suite of assertions that can be run on a CDK stack.
@@ -74,7 +75,7 @@ export class Template {
74
75
public resourceCountIs ( type : string , count : number ) : void {
75
76
const counted = countResources ( this . template , type ) ;
76
77
if ( counted !== count ) {
77
- throw new Error ( `Expected ${ count } resources of type ${ type } but found ${ counted } ` ) ;
78
+ throw new AssertionError ( `Expected ${ count } resources of type ${ type } but found ${ counted } ` ) ;
78
79
}
79
80
}
80
81
@@ -88,7 +89,7 @@ export class Template {
88
89
public resourcePropertiesCountIs ( type : string , props : any , count : number ) : void {
89
90
const counted = countResourcesProperties ( this . template , type , props ) ;
90
91
if ( counted !== count ) {
91
- throw new Error ( `Expected ${ count } resources of type ${ type } but found ${ counted } ` ) ;
92
+ throw new AssertionError ( `Expected ${ count } resources of type ${ type } but found ${ counted } ` ) ;
92
93
}
93
94
}
94
95
@@ -103,7 +104,7 @@ export class Template {
103
104
public hasResourceProperties ( type : string , props : any ) : void {
104
105
const matchError = hasResourceProperties ( this . template , type , props ) ;
105
106
if ( matchError ) {
106
- throw new Error ( matchError ) ;
107
+ throw new AssertionError ( matchError ) ;
107
108
}
108
109
}
109
110
@@ -118,7 +119,7 @@ export class Template {
118
119
public hasResource ( type : string , props : any ) : void {
119
120
const matchError = hasResource ( this . template , type , props ) ;
120
121
if ( matchError ) {
121
- throw new Error ( matchError ) ;
122
+ throw new AssertionError ( matchError ) ;
122
123
}
123
124
}
124
125
@@ -144,7 +145,7 @@ export class Template {
144
145
public allResources ( type : string , props : any ) : void {
145
146
const matchError = allResources ( this . template , type , props ) ;
146
147
if ( matchError ) {
147
- throw new Error ( matchError ) ;
148
+ throw new AssertionError ( matchError ) ;
148
149
}
149
150
}
150
151
@@ -159,7 +160,7 @@ export class Template {
159
160
public allResourcesProperties ( type : string , props : any ) : void {
160
161
const matchError = allResourcesProperties ( this . template , type , props ) ;
161
162
if ( matchError ) {
162
- throw new Error ( matchError ) ;
163
+ throw new AssertionError ( matchError ) ;
163
164
}
164
165
}
165
166
@@ -173,7 +174,7 @@ export class Template {
173
174
public hasParameter ( logicalId : string , props : any ) : void {
174
175
const matchError = hasParameter ( this . template , logicalId , props ) ;
175
176
if ( matchError ) {
176
- throw new Error ( matchError ) ;
177
+ throw new AssertionError ( matchError ) ;
177
178
}
178
179
}
179
180
@@ -198,7 +199,7 @@ export class Template {
198
199
public hasOutput ( logicalId : string , props : any ) : void {
199
200
const matchError = hasOutput ( this . template , logicalId , props ) ;
200
201
if ( matchError ) {
201
- throw new Error ( matchError ) ;
202
+ throw new AssertionError ( matchError ) ;
202
203
}
203
204
}
204
205
@@ -223,7 +224,7 @@ export class Template {
223
224
public hasMapping ( logicalId : string , props : any ) : void {
224
225
const matchError = hasMapping ( this . template , logicalId , props ) ;
225
226
if ( matchError ) {
226
- throw new Error ( matchError ) ;
227
+ throw new AssertionError ( matchError ) ;
227
228
}
228
229
}
229
230
@@ -248,7 +249,7 @@ export class Template {
248
249
public hasCondition ( logicalId : string , props : any ) : void {
249
250
const matchError = hasCondition ( this . template , logicalId , props ) ;
250
251
if ( matchError ) {
251
- throw new Error ( matchError ) ;
252
+ throw new AssertionError ( matchError ) ;
252
253
}
253
254
}
254
255
@@ -272,7 +273,7 @@ export class Template {
272
273
const result = matcher . test ( this . template ) ;
273
274
274
275
if ( result . hasFailed ( ) ) {
275
- throw new Error ( [
276
+ throw new AssertionError ( [
276
277
'Template did not match as expected. The following mismatches were found:' ,
277
278
...result . toHumanStrings ( ) . map ( s => `\t${ s } ` ) ,
278
279
] . join ( '\n' ) ) ;
@@ -297,7 +298,7 @@ export interface TemplateParsingOptions {
297
298
function toTemplate ( stack : Stack ) : any {
298
299
const stage = Stage . of ( stack ) ;
299
300
if ( ! Stage . isStage ( stage ) ) {
300
- throw new Error ( 'unexpected: all stacks must be part of a Stage or an App' ) ;
301
+ throw new AssertionError ( 'unexpected: all stacks must be part of a Stage or an App' ) ;
301
302
}
302
303
303
304
const assembly = stage . synth ( ) ;
0 commit comments