mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-15 12:07:42 +00:00
Merge pull request #7591 from keymanapp/feat/developer/epic-ldml/improve-errmsg
feat(developer): improve err msg from Ajv 🙀
This commit is contained in:
commit
8cd7dbb768
1 changed files with 10 additions and 1 deletions
|
|
@ -62,7 +62,16 @@ export default class LDMLKeyboardXMLSourceFileReader {
|
|||
const schema = JSON.parse(schemaSource.toString('utf8'));
|
||||
const ajv = new Ajv();
|
||||
if(!ajv.validate(schema, source)) {
|
||||
throw new Error(ajv.errorsText());
|
||||
// Try to improve the message
|
||||
if (ajv.errors?.length === 1) {
|
||||
// Only one error. Try to improve the message.
|
||||
const err = ajv.errors[0];
|
||||
const { instancePath, keyword, params, message } = err;
|
||||
throw new Error(`${instancePath}: ${keyword}: ${message} ${JSON.stringify(params||{})}`);
|
||||
} else {
|
||||
// Not a single error, so fall through to errorsText()
|
||||
throw new Error(ajv.errorsText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue