From a212aefeececfdd8636a972e83fc201d347af47c Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Tue, 1 Nov 2022 16:29:03 -0500 Subject: [PATCH] =?UTF-8?q?feat(developer):=20improve=20err=20msg=20from?= =?UTF-8?q?=20Ajv=20=F0=9F=99=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - make it clearer what the exact issue is by extracting params from the Ajv error --- .../src/ldml-keyboard/ldml-keyboard-xml-reader.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/web/types/src/ldml-keyboard/ldml-keyboard-xml-reader.ts b/common/web/types/src/ldml-keyboard/ldml-keyboard-xml-reader.ts index 64dd40ded4..6d34a8a309 100644 --- a/common/web/types/src/ldml-keyboard/ldml-keyboard-xml-reader.ts +++ b/common/web/types/src/ldml-keyboard/ldml-keyboard-xml-reader.ts @@ -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()); + } } }