diff --git a/src/process/validation/rules/validateMaximumSelectedCount.ts b/src/process/validation/rules/validateMaximumSelectedCount.ts index cb4562cd..d093dfe3 100644 --- a/src/process/validation/rules/validateMaximumSelectedCount.ts +++ b/src/process/validation/rules/validateMaximumSelectedCount.ts @@ -28,16 +28,20 @@ export const shouldValidate = (context: ValidationContext) => { return true; }; -function validateValue(value: DataObject[any]): asserts value is Record { +function validateValue(value: DataObject[any], context: ValidationContext): asserts value is Record { if (value == null || typeof value !== 'object') { - throw new Error( - `Cannot validate maximum selected count for value ${value} as it is not an object` + throw new ProcessorError( + `Cannot validate maximum selected count for value ${value} as it is not an object`, + context, + 'validate:validateMaximumSelectedCount' ); } const subValues = Object.values(value); if (!subValues.every((value) => typeof value === 'boolean')) { - throw new Error( - `Cannot validate maximum selected count for value ${value} because it has non-boolean members` + throw new ProcessorError( + `Cannot validate maximum selected count for value ${value} because it has non-boolean members`, + context, + 'validate:validateMaximumSelectedCount' ); } } @@ -53,7 +57,7 @@ export const validateMaximumSelectedCountSync: RuleFnSync = (context: Validation if (!shouldValidate(context)) { return null; } - validateValue(value); + validateValue(value, context); const max = getValidationSetting(component as SelectBoxesComponent); if (!max) { return null; diff --git a/src/process/validation/rules/validateMinimumSelectedCount.ts b/src/process/validation/rules/validateMinimumSelectedCount.ts index 1e1b2c31..70efcf40 100644 --- a/src/process/validation/rules/validateMinimumSelectedCount.ts +++ b/src/process/validation/rules/validateMinimumSelectedCount.ts @@ -28,16 +28,20 @@ export const shouldValidate = (context: ValidationContext) => { return true; }; -function validateValue(value: DataObject[any]): asserts value is Record { +function validateValue(value: DataObject[any], context: ValidationContext): asserts value is Record { if (value == null || typeof value !== 'object') { - throw new Error( - `Cannot validate maximum selected count for value ${value} as it is not an object` + throw new ProcessorError( + `Cannot validate maximum selected count for value ${value} as it is not an object`, + context, + 'validate:validateMinimumSelectedCount' ); } const subValues = Object.values(value); if (!subValues.every((value) => typeof value === 'boolean')) { - throw new Error( - `Cannot validate maximum selected count for value ${value} because it has non-boolean members` + throw new ProcessorError( + `Cannot validate maximum selected count for value ${value} because it has non-boolean members`, + context, + 'validate:validateMinimumSelectedCount' ); } } @@ -53,7 +57,7 @@ export const validateMinimumSelectedCountSync: RuleFnSync = (context: Validation if (!shouldValidate(context)) { return null; } - validateValue(value); + validateValue(value, context); const min = getValidationSetting((component as SelectBoxesComponent)); if (!min) { return null;