Skip to content

Commit

Permalink
fix(@angular-devkit/architect): propagate option validation errors
Browse files Browse the repository at this point in the history
    By using the `SchemaValidationException` object, the underlying JSON schema validation errors will be propagated to the consuming code.  This allows for more detailed error reporting of malformed or incorrectly provided options.

Partially addresses #14269
  • Loading branch information
clydin authored and alexeagle committed Apr 26, 2019
1 parent 25b3615 commit 0368b89
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 2 additions & 4 deletions packages/angular_devkit/architect/src/architect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function _createJobHandlerFromBuilderInfo(
if (result.success) {
return { ...v, options: result.data } as BuilderInput;
} else if (result.errors) {
throw new Error('Options did not validate.' + result.errors.join());
throw new json.schema.SchemaValidationException(result.errors);
} else {
return v;
}
Expand Down Expand Up @@ -282,9 +282,7 @@ function _validateOptionsFactory(host: ArchitectHost, registry: json.schema.Sche
if (success) {
return of(data as json.JsonObject);
} else {
throw new Error(
'Data did not validate: ' + (errors ? errors.join() : 'Unknown error.'),
);
throw new json.schema.SchemaValidationException(errors);
}
}),
).toPromise();
Expand Down
7 changes: 3 additions & 4 deletions packages/angular_devkit/architect/src/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,9 @@ describe('architect', () => {
// Should also error.
const run2 = await architect.scheduleBuilder('package:do-it', {});

try {
await run2.output.toPromise();
expect('THE ABOVE LINE SHOULD NOT ERROR').toBe('false');
} catch {}
await expectAsync(run2.output.toPromise())
.toBeRejectedWith(jasmine.objectContaining({ message: jasmine.stringMatching('p1')}));

await run2.stop();
});
});

0 comments on commit 0368b89

Please sign in to comment.