Skip to content

Commit

Permalink
fix omission of processorerror
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond committed Apr 8, 2024
1 parent 6aed425 commit b18b7be
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/process/validation/rules/validateAvailableItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function mapStaticValues(values: { label: string; value: string }[]) {
return values.map((obj) => obj.value);
}

async function getAvailableSelectValues(component: SelectComponent) {
async function getAvailableSelectValues(component: SelectComponent, context: ValidationContext) {
switch (component.dataSrc) {
case 'values':
if (Array.isArray(component.data.values)) {
Expand Down Expand Up @@ -76,8 +76,10 @@ async function getAvailableSelectValues(component: SelectComponent) {
if (Array.isArray(resolvedCustomItems)) {
return resolvedCustomItems;
}
throw new Error(
`Failed to validate available values in JSON select component '${component.key}': the values are not an array`
throw new ProcessorError(
`Failed to validate available values in JSON select component '${component.key}': the values are not an array`,
context,
'validate:validateAvailableItems'
);
}
if (Array.isArray(customItems)) {
Expand All @@ -94,7 +96,7 @@ async function getAvailableSelectValues(component: SelectComponent) {
}
}

function getAvailableSelectValuesSync(component: SelectComponent) {
function getAvailableSelectValuesSync(component: SelectComponent, context: ValidationContext) {
switch (component.dataSrc) {
case 'values':
if (Array.isArray(component.data?.values)) {
Expand All @@ -108,16 +110,20 @@ function getAvailableSelectValuesSync(component: SelectComponent) {
try {
return mapDynamicValues(component, JSON.parse(component.data.json));
} catch (err) {
throw new Error(
`Failed to validate available values in JSON select component '${component.key}': ${err}`
throw new ProcessorError(
`Failed to validate available values in JSON select component '${component.key}': ${err}`,
context,
'validate:validateAvailableItems'
);
}
} else if (Array.isArray(component.data.json)) {
// TODO: need to retype this
return mapDynamicValues(component, component.data.json as Record<string, any>[]);
} else {
throw new Error(
`Failed to validate available values in JSON select component '${component.key}': the values are not an array`
throw new ProcessorError(
`Failed to validate available values in JSON select component '${component.key}': the values are not an array`,
context,
'validate:validateAvailableItems'
);
}
}
Expand Down Expand Up @@ -178,7 +184,7 @@ export const validateAvailableItems: RuleFn = async (context: ValidationContext)
if (value == null || isEmpty(value)) {
return null;
}
const values = await getAvailableSelectValues(component);
const values = await getAvailableSelectValues(component, context);
if (values) {
if (isObject(value)) {
return values.find((optionValue) => compareComplexValues(optionValue, value)) !==
Expand Down Expand Up @@ -227,7 +233,7 @@ export const validateAvailableItemsSync: RuleFnSync = (context: ValidationContex
}
return null;
} else if (isValidateableSelectComponent(component)) {
const values = getAvailableSelectValuesSync(component);
const values = getAvailableSelectValuesSync(component, context);
if (values) {
if (isObject(value)) {
return values.find((optionValue) => compareComplexValues(optionValue, value)) !==
Expand Down

0 comments on commit b18b7be

Please sign in to comment.