Skip to content

Commit 878d145

Browse files
committed
return keyerror and raise from origin, as requested in code review
1 parent 7417f43 commit 878d145

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Rules.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class LogicErrorSource(IntEnum):
2121
EVALUATE_POSTFIX = 2 # includes missing pipes and missing value on either side of AND/OR
2222
EVALUATE_STACK_SIZE = 3 # includes missing curly brackets
2323

24-
def raise_logic_error(location_or_region: dict, source: LogicErrorSource):
24+
def construct_logic_error(location_or_region: dict, source: LogicErrorSource) -> KeyError:
2525
object_type = "location/region"
2626
object_name = location_or_region.get("name", "Unknown")
2727

@@ -39,7 +39,7 @@ def raise_logic_error(location_or_region: dict, source: LogicErrorSource):
3939
else:
4040
source_text = "This requires includes invalid syntax."
4141

42-
raise KeyError(f"Invalid 'requires' for {object_type} '{object_name}': {source_text} (ERROR {source})")
42+
return KeyError(f"Invalid 'requires' for {object_type} '{object_name}': {source_text} (ERROR {source})")
4343

4444
def infix_to_postfix(expr, location):
4545
prec = {"&": 2, "|": 2, "!": 3}
@@ -64,7 +64,7 @@ def infix_to_postfix(expr, location):
6464
while stack:
6565
postfix += stack.pop()
6666
except Exception:
67-
raise_logic_error(location, LogicErrorSource.INFIX_TO_POSTFIX)
67+
raise construct_logic_error(location, LogicErrorSource.INFIX_TO_POSTFIX)
6868

6969
return postfix
7070

@@ -90,10 +90,10 @@ def evaluate_postfix(expr: str, location: str) -> bool:
9090
op = stack.pop()
9191
stack.append(not op)
9292
except Exception:
93-
raise_logic_error(location, LogicErrorSource.EVALUATE_POSTFIX)
93+
raise construct_logic_error(location, LogicErrorSource.EVALUATE_POSTFIX)
9494

9595
if len(stack) != 1:
96-
raise_logic_error(location, LogicErrorSource.EVALUATE_STACK_SIZE)
96+
raise construct_logic_error(location, LogicErrorSource.EVALUATE_STACK_SIZE)
9797

9898
return stack.pop()
9999

0 commit comments

Comments
 (0)