mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 02:24:10 +08:00
feat(@angular-devkit/core): provide prompt validation errors to provider
This change provides the first schema validation error to a prompt provider when using a prompt definition's `validate` function. This allows a prompt provider to show additional context to a user when an entered value is invalid.
This commit is contained in:
parent
5fdc0a666a
commit
d62441f183
@ -599,10 +599,22 @@ export class CoreSchemaRegistry implements SchemaRegistry {
|
||||
: (parentSchema as JsonObject).default as string[],
|
||||
async validator(data: JsonValue) {
|
||||
try {
|
||||
return await it.self.validate(parentSchema, data);
|
||||
} catch {
|
||||
return false;
|
||||
const result = await it.self.validate(parentSchema, data);
|
||||
// If the schema is sync then false will be returned on validation failure
|
||||
if (result) {
|
||||
return result;
|
||||
} else if (it.self.errors?.length) {
|
||||
// Validation errors will be present on the Ajv instance when sync
|
||||
return it.self.errors[0].message;
|
||||
}
|
||||
} catch (e) {
|
||||
// If the schema is async then an error will be thrown on validation failure
|
||||
if (Array.isArray(e.errors) && e.errors.length) {
|
||||
return e.errors[0].message;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user