diff --git a/src/ytdl_sub/script/parser.py b/src/ytdl_sub/script/parser.py index a2423134..30a24d4d 100644 --- a/src/ytdl_sub/script/parser.py +++ b/src/ytdl_sub/script/parser.py @@ -188,7 +188,8 @@ class _Parser: elif ch == ",": comma_count += 1 if argument_index != comma_count: - raise StringFormattingException("Comma argument shenanigans") + self._set_highlight_position() + raise InvalidSyntaxException("Unexpected comma when parsing arguments") self._pos += 1 else: @@ -252,7 +253,7 @@ class _Parser: if key is not None: raise InvalidSyntaxException("Map has a key with no value") if output is None: - raise StringFormattingException("Empty dict with comma") + raise InvalidSyntaxException("Map has an extra comma") in_comma = True self._pos += 1 elif key is None: diff --git a/tests/unit/script/types/test_map.py b/tests/unit/script/types/test_map.py index 73a4e28a..cce577b7 100644 --- a/tests/unit/script/types/test_map.py +++ b/tests/unit/script/types/test_map.py @@ -74,3 +74,16 @@ class TestMap: def test_key_has_no_value(self, value: str): with pytest.raises(InvalidSyntaxException, match=re.escape("Map has a key with no value")): Script({"map": value}).resolve() + + @pytest.mark.parametrize( + "value", + [ + "{{ , }}", + "{{'key': 'value', ,}}", + ], + ) + def test_map_unexpected_comma(self, value: str): + with pytest.raises( + InvalidSyntaxException, match=re.escape("Unexpected comma when parsing arguments") + ): + Script({"map": value}).resolve()