From 2fce1ff2ab27351925f0e24b7b04303e5efa1a72 Mon Sep 17 00:00:00 2001 From: pedohorse <13556996+pedohorse@users.noreply.github.com> Date: Sat, 31 Aug 2024 22:18:43 +0200 Subject: [PATCH] implement parameter input validation --- src/lifeblood/core_nodes/wedge.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lifeblood/core_nodes/wedge.py b/src/lifeblood/core_nodes/wedge.py index 3bc12a49..1aa28559 100644 --- a/src/lifeblood/core_nodes/wedge.py +++ b/src/lifeblood/core_nodes/wedge.py @@ -46,15 +46,24 @@ def process_task(self, context) -> ProcessingResult: if wedges_count <= 0: return ProcessingResult() wedge_ranges = [] + attribute_names = set() # to check for duplication for i in range(wedges_count): wtype = context.param_value(f'wtype_{i}') + attr_name = context.param_value(f'attr_{i}') + attr_name = attr_name.strip() + if not attr_name: + raise ProcessingError('wedged attribute must not be empty.') + if attr_name in attribute_names: + raise ProcessingError(f'Each attribute must only appear once in the list. Attribute named "{attr_name}" is duplicated') + attribute_names.add(attr_name) + if wtype == 0: count = context.param_value(f'count_{i}') if count <= 0: raise ProcessingError('count cannot be less or equal to zero') - wedge_ranges.append((0, context.param_value(f'attr_{i}'), context.param_value(f'from_{i}'), context.param_value(f'to_{i}'), count)) + wedge_ranges.append((0, attr_name, context.param_value(f'from_{i}'), context.param_value(f'to_{i}'), count)) elif wtype == 1: - wedge_ranges.append((1, context.param_value(f'attr_{i}'), context.param_value(f'from_{i}'), context.param_value(f'max_{i}'), context.param_value(f'inc_{i}'))) + wedge_ranges.append((1, attr_name, context.param_value(f'from_{i}'), context.param_value(f'max_{i}'), context.param_value(f'inc_{i}'))) else: raise ProcessingError('bad wedge type')