From 2ffc82c864878e0d212bbfa6582044555ba6fc78 Mon Sep 17 00:00:00 2001 From: Viren070 Date: Sun, 22 Jun 2025 14:07:38 +0100 Subject: [PATCH] feat: loop through optionMetas to ensure new options are validated too and ignore individual errors from presets when necessary --- packages/core/src/utils/config.ts | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/core/src/utils/config.ts b/packages/core/src/utils/config.ts index 43bc5004..b770ce40 100644 --- a/packages/core/src/utils/config.ts +++ b/packages/core/src/utils/config.ts @@ -296,7 +296,14 @@ export async function validateConfig( ); } instanceIds.add(preset.instanceId); - validatePreset(preset); + try { + validatePreset(preset); + } catch (error) { + if (!skipErrorsFromAddonsOrProxies) { + throw error; + } + logger.warn(`Invalid preset ${preset.instanceId}: ${error}`); + } } } @@ -488,14 +495,10 @@ function validatePreset(preset: PresetObject) { const optionMetas = presetMeta.OPTIONS; - for (const [optionId, optionValue] of Object.entries(preset.options)) { - const optionMeta = optionMetas.find((option) => option.id === optionId); - if (!optionMeta) { - continue; - // throw new Error(`Option ${optionId} not found in preset ${preset.id}`); - } + for (const optionMeta of optionMetas) { + const optionValue = preset.options[optionMeta.id]; try { - preset.options[optionId] = validateOption(optionMeta, optionValue); + preset.options[optionMeta.id] = validateOption(optionMeta, optionValue); } catch (error) { throw new Error( `The value for option '${optionMeta.name}' in preset '${presetMeta.NAME}' is invalid: ${error}` @@ -535,6 +538,12 @@ function validateOption( value: any, decryptValues: boolean = false ): any { + if (value === undefined) { + if (option.required) { + throw new Error(`Option ${option.id} is required, got ${value}`); + } + return value; + } if (option.type === 'multi-select') { if (!Array.isArray(value)) { throw new Error( @@ -605,10 +614,6 @@ function validateOption( } } - if (option.required && value === undefined) { - throw new Error(`Option ${option.id} is required, got ${value}`); - } - return value; }