Skip to content

Commit

Permalink
implement parameter input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
pedohorse committed Sep 1, 2024
1 parent 2834cdb commit 2fce1ff
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lifeblood/core_nodes/wedge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down

0 comments on commit 2fce1ff

Please sign in to comment.