Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): turn validation errors into metadata errors #2988

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/@aws-cdk/cdk/lib/construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ export class ConstructNode {
const validate = options.skipValidation === undefined ? true : !options.skipValidation;
if (validate) {
const errors = this.validate(root);
if (errors.length > 0) {
const errorList = errors.map(e => `[${e.source.node.path}] ${e.message}`).join('\n ');
throw new Error(`Validation failed with the following errors:\n ${errorList}`);
}
// Turn the errors into metadata errors, so they will prevent deploying but will not
// prevent CDK from executing again.
errors.forEach(e => {
e.source.node.addError(e.message);
});
}

// synthesize (leaves first)
Expand Down
6 changes: 5 additions & 1 deletion packages/@aws-cdk/cdk/test/test.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ export = {
new Child(parent, 'C1');
new Child(parent, 'C2');

test.throws(() => app.synth(), /Validation failed with the following errors/);
const assembly = app.synth();
test.deepEqual(assembly.getStack('Parent').messages.filter(m => m.level === cxapi.SynthesisMessageLevel.ERROR).map(m => m.entry.data), [
'Error from C1',
'Error from C2',
]);

test.done();
},
Expand Down