From 877c3fb94e7627f5f3d24632112fdd956ccb0a1b Mon Sep 17 00:00:00 2001 From: robcxyz Date: Mon, 20 Mar 2023 04:44:40 +0530 Subject: [PATCH] fix: add better exception handling for hook call --- tackle/macros.py | 3 +++ tests/parser/exceptions/empty-hook-call.yaml | 1 + tests/parser/test_parser_exceptions.py | 20 ++++++++------------ 3 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 tests/parser/exceptions/empty-hook-call.yaml diff --git a/tackle/macros.py b/tackle/macros.py index 0262ad024..0c02aaaba 100644 --- a/tackle/macros.py +++ b/tackle/macros.py @@ -68,6 +68,9 @@ def blocks_macro(context: 'Context'): ) value = input_dict[indexed_key_path[-1]] + if value is None: + raise exceptions.HookCallException("Empty hook call found.", context=context) + for k, v in list(input_dict.items()): if k == indexed_key_path[-1]: nested_set(context.input_context, key_path, {arrow[0]: 'block'}) diff --git a/tests/parser/exceptions/empty-hook-call.yaml b/tests/parser/exceptions/empty-hook-call.yaml new file mode 100644 index 000000000..a04c946ca --- /dev/null +++ b/tests/parser/exceptions/empty-hook-call.yaml @@ -0,0 +1 @@ +foo->: \ No newline at end of file diff --git a/tests/parser/test_parser_exceptions.py b/tests/parser/test_parser_exceptions.py index 6c39d50df..9654ce9c3 100644 --- a/tests/parser/test_parser_exceptions.py +++ b/tests/parser/test_parser_exceptions.py @@ -1,24 +1,20 @@ """Test the input source part of the parser.""" import pytest -from tackle.exceptions import ( - EmptyTackleFileException, - UnknownArgumentException, - UnknownSourceException, - HookParseException, -) +from tackle import exceptions # from tackle import tackle from tackle.cli import main INPUT_SOURCES = [ # TODO: empty should now be running help screen - # ("empty-with-functions.yaml", EmptyTackleFileException), - ("empty.yaml", EmptyTackleFileException), - ("out-of-range-arg.yaml", UnknownArgumentException), - ("non-existent.yaml", UnknownSourceException), - ("hook-input-validation-error.yaml", HookParseException), - ("function-input-validation-error.yaml", HookParseException), + # ("empty-with-functions.yaml", exceptions.EmptyTackleFileException), + ("empty-hook-call.yaml", exceptions.HookCallException), + ("empty.yaml", exceptions.EmptyTackleFileException), + ("out-of-range-arg.yaml", exceptions.UnknownArgumentException), + ("non-existent.yaml", exceptions.UnknownSourceException), + ("hook-input-validation-error.yaml", exceptions.HookParseException), + ("function-input-validation-error.yaml", exceptions.HookParseException), ]