From 2c99e83d52316ff86bd16584394661e253dc5e89 Mon Sep 17 00:00:00 2001 From: KV Date: Thu, 25 Mar 2021 20:09:22 +0100 Subject: [PATCH] Revert "Use a generator expressions and raise exception if failing" This reverts commit 96d393dfb757afc61ffb319c34035d8d2ce7c33d. However, raising an exception if failing the BOM index search is still wanted, so a custom exception is raised instead of returning None. --- src/wireviz/wv_bom.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index f71abc1..99a9fd6 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -118,10 +118,13 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]: return [{**entry, 'id': index} for index, entry in enumerate(bom, 1)] def get_bom_index(bom: List[BOMEntry], part: AdditionalComponent) -> int: - """Return id of BOM entry or raise StopIteration if not found.""" + """Return id of BOM entry or raise exception if not found.""" # Remove linebreaks and clean whitespace of values in search target = tuple(clean_whitespace(v) for v in bom_types_group({**asdict(part), 'description': part.description})) - return next(entry['id'] for entry in bom if bom_types_group(entry) == target) + for entry in bom: + if bom_types_group(entry) == target: + return entry['id'] + raise Exception('Internal error: No BOM entry found matching: ' + '|'.join(target)) def bom_list(bom: List[BOMEntry]) -> List[List[str]]: """Return list of BOM rows as lists of column strings with headings in top row."""