Skip to content

Commit 5f24820

Browse files
clydinalexeagle
authored andcommitted
fix(@angular-devkit/architect): propagate option validation errors
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 angular#14269
1 parent 5b4b78b commit 5f24820

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

packages/angular_devkit/architect/src/architect.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function _createJobHandlerFromBuilderInfo(
5555
if (result.success) {
5656
return { ...v, options: result.data } as BuilderInput;
5757
} else if (result.errors) {
58-
throw new Error('Options did not validate.' + result.errors.join());
58+
throw new json.schema.SchemaValidationException(result.errors);
5959
} else {
6060
return v;
6161
}
@@ -282,9 +282,7 @@ function _validateOptionsFactory(host: ArchitectHost, registry: json.schema.Sche
282282
if (success) {
283283
return of(data as json.JsonObject);
284284
} else {
285-
throw new Error(
286-
'Data did not validate: ' + (errors ? errors.join() : 'Unknown error.'),
287-
);
285+
throw new json.schema.SchemaValidationException(errors);
288286
}
289287
}),
290288
).toPromise();

packages/angular_devkit/architect/src/index_spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,9 @@ describe('architect', () => {
300300
// Should also error.
301301
const run2 = await architect.scheduleBuilder('package:do-it', {});
302302

303-
try {
304-
await run2.output.toPromise();
305-
expect('THE ABOVE LINE SHOULD NOT ERROR').toBe('false');
306-
} catch {}
303+
await expectAsync(run2.output.toPromise())
304+
.toBeRejectedWith(jasmine.objectContaining({ message: jasmine.stringMatching('p1')}));
305+
307306
await run2.stop();
308307
});
309308
});

0 commit comments

Comments
 (0)