Skip to content

Commit 2fe2b46

Browse files
committed
communicate with console error if it fails
1 parent 09072b6 commit 2fe2b46

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Umbraco.Web.UI.Client/src/packages/core/validation/controllers/validation.controller.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
131131
this.#parentMessages = msgs;
132132
msgs.forEach((msg) => {
133133
const path = ReplaceStartOfPath(msg.path, this.#baseDataPath!, '$');
134+
if (path === undefined) {
135+
throw new Error(
136+
'Path was not transformed correctly and can therefor not be transfered to the local validation context messages.',
137+
);
138+
}
134139
// Notice, the local message uses the same key. [NL]
135140
this.messages.addMessage(msg.type, path, msg.body, msg.key);
136141
});
@@ -152,6 +157,11 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
152157
msgs.forEach((msg) => {
153158
// replace this.#baseDataPath (if it starts with it) with $ in the path, so it becomes relative to the parent context
154159
const path = ReplaceStartOfPath(msg.path, '$', this.#baseDataPath!);
160+
if (path === undefined) {
161+
throw new Error(
162+
'Path was not transformed correctly and can therefor not be synced with parent messages.',
163+
);
164+
}
155165
// Notice, the parent message uses the same key. [NL]
156166
this.#parent!.messages.addMessage(msg.type, path, msg.body, msg.key);
157167
});

src/Umbraco.Web.UI.Client/src/packages/core/validation/utils/replace-start-of-path.function.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
* @param startTo {string}
66
* @returns {string}
77
*/
8-
export function ReplaceStartOfPath(path: string, startFrom: string, startTo: string): string {
8+
export function ReplaceStartOfPath(path: string, startFrom: string, startTo: string): string | undefined {
99
// if the path conitnues with a . or [ aftr startFrom, then replace it with startTo, otherwise if identical then it is also a match. [NL]
1010
if (path.startsWith(startFrom + '.') || path === startFrom) {
1111
return startTo + path.slice(startFrom.length);
1212
}
13-
return path;
13+
return;
1414
}

0 commit comments

Comments
 (0)