Skip to content

Commit

Permalink
fix: add better exception handling for missing key in match hook
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Mar 14, 2023
1 parent 8d3e973 commit 64c9ee1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tackle/providers/logic/hooks/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def exec(self) -> Union[dict, list]:
context=self,
) from None

raise Exception(f"Value `{self.value}` not found in {self.case.keys()}")
raise HookCallException(
f"Value `{self.value}` not found in "
f"{' ,'.join([i for i in list(self.case)])}",
context=self,
) from None

def run_key(self, value):
self.skip_output: bool = True
Expand Down
8 changes: 8 additions & 0 deletions tackle/providers/logic/tests/match/non-existant-key.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


foo: bar

error:
->: match foo
case:
baz: biz
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ def test_hook_match_value_wrong_hook_type(change_dir):
"""
with pytest.raises(HookCallException):
tackle('wrong-hook-type.yaml')


def test_hook_match_non_existant_key(change_dir):
with pytest.raises(HookCallException):
tackle('non-existant-key.yaml')

0 comments on commit 64c9ee1

Please sign in to comment.