From a2398cfb7ecc806caa71152293f3b868134cee87 Mon Sep 17 00:00:00 2001 From: Yasunobu Chiba <724165+chibacchie@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:18:39 +0900 Subject: [PATCH] Make error messages consistent. Fixes #2514. --- lib/vocabularies/applicator/dependencies.ts | 6 +++++- spec/errors.spec.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/vocabularies/applicator/dependencies.ts b/lib/vocabularies/applicator/dependencies.ts index f67611286..659db68e1 100644 --- a/lib/vocabularies/applicator/dependencies.ts +++ b/lib/vocabularies/applicator/dependencies.ts @@ -30,7 +30,11 @@ export type DependenciesError = ErrorObject< export const error: KeywordErrorDefinition = { message: ({params: {property, depsCount, deps}}) => { const property_ies = depsCount === 1 ? "property" : "properties" - return str`must have ${property_ies} ${deps} when property ${property} is present` + const quotedDeps = (deps as string) + .split(", ") + .map((v) => `'${v}'`) + .join(", ") + return str`must have ${property_ies} ${quotedDeps} when property '${property}' is present` }, params: ({params: {property, depsCount, deps, missingProperty}}) => _`{property: ${property}, diff --git a/spec/errors.spec.ts b/spec/errors.spec.ts index 5f075845e..a23c2c86c 100644 --- a/spec/errors.spec.ts +++ b/spec/errors.spec.ts @@ -393,7 +393,7 @@ describe("Validation errors", () => { invalidData1 = {a: 0, foo: 1, baz: 3}, invalidData2 = {a: 0, bar: 2} - const msg = "must have properties foo, bar, baz when property a is present" + const msg = "must have properties 'foo', 'bar', 'baz' when property 'a' is present" const validate = ajv.compile(schema) shouldBeValid(validate, data)