From 2fe2b466701118293be792acdd3115a86780afdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Fri, 31 Jan 2025 21:17:45 +0100 Subject: [PATCH] communicate with console error if it fails --- .../validation/controllers/validation.controller.ts | 10 ++++++++++ .../validation/utils/replace-start-of-path.function.ts | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/validation/controllers/validation.controller.ts b/src/Umbraco.Web.UI.Client/src/packages/core/validation/controllers/validation.controller.ts index ce7e4cbcea..87a7d04db7 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/validation/controllers/validation.controller.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/validation/controllers/validation.controller.ts @@ -131,6 +131,11 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal this.#parentMessages = msgs; msgs.forEach((msg) => { const path = ReplaceStartOfPath(msg.path, this.#baseDataPath!, '$'); + if (path === undefined) { + throw new Error( + 'Path was not transformed correctly and can therefor not be transfered to the local validation context messages.', + ); + } // Notice, the local message uses the same key. [NL] this.messages.addMessage(msg.type, path, msg.body, msg.key); }); @@ -152,6 +157,11 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal msgs.forEach((msg) => { // replace this.#baseDataPath (if it starts with it) with $ in the path, so it becomes relative to the parent context const path = ReplaceStartOfPath(msg.path, '$', this.#baseDataPath!); + if (path === undefined) { + throw new Error( + 'Path was not transformed correctly and can therefor not be synced with parent messages.', + ); + } // Notice, the parent message uses the same key. [NL] this.#parent!.messages.addMessage(msg.type, path, msg.body, msg.key); }); diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/validation/utils/replace-start-of-path.function.ts b/src/Umbraco.Web.UI.Client/src/packages/core/validation/utils/replace-start-of-path.function.ts index 8e34feeaf4..b8d2e53184 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/validation/utils/replace-start-of-path.function.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/validation/utils/replace-start-of-path.function.ts @@ -5,10 +5,10 @@ * @param startTo {string} * @returns {string} */ -export function ReplaceStartOfPath(path: string, startFrom: string, startTo: string): string { +export function ReplaceStartOfPath(path: string, startFrom: string, startTo: string): string | undefined { // if the path conitnues with a . or [ aftr startFrom, then replace it with startTo, otherwise if identical then it is also a match. [NL] if (path.startsWith(startFrom + '.') || path === startFrom) { return startTo + path.slice(startFrom.length); } - return path; + return; }