Skip to content

Commit

Permalink
finally remove all Error objects to ProcessorError
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond committed Apr 16, 2024
1 parent 959a9ac commit 9d5d1d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
16 changes: 10 additions & 6 deletions src/process/validation/rules/validateMaximumSelectedCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ export const shouldValidate = (context: ValidationContext) => {
return true;
};

function validateValue(value: DataObject[any]): asserts value is Record<string, boolean> {
function validateValue(value: DataObject[any], context: ValidationContext): asserts value is Record<string, boolean> {
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'
);
}
}
Expand All @@ -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;
Expand Down
16 changes: 10 additions & 6 deletions src/process/validation/rules/validateMinimumSelectedCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ export const shouldValidate = (context: ValidationContext) => {
return true;
};

function validateValue(value: DataObject[any]): asserts value is Record<string, boolean> {
function validateValue(value: DataObject[any], context: ValidationContext): asserts value is Record<string, boolean> {
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'
);
}
}
Expand All @@ -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;
Expand Down

0 comments on commit 9d5d1d9

Please sign in to comment.