From 469d03777ec7fd38542e3f9c72345b5a65deed87 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Fri, 10 Nov 2023 15:29:00 -0800 Subject: [PATCH] unreachable --- src/ytdl_sub/script/parser.py | 13 ++++++++++--- src/ytdl_sub/script/utils/exceptions.py | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ytdl_sub/script/parser.py b/src/ytdl_sub/script/parser.py index 86ea1e2e..2f275c2d 100644 --- a/src/ytdl_sub/script/parser.py +++ b/src/ytdl_sub/script/parser.py @@ -16,12 +16,19 @@ from ytdl_sub.script.types.syntax_tree import SyntaxTree from ytdl_sub.script.types.variable import FunctionArgument from ytdl_sub.script.types.variable import Variable from ytdl_sub.script.utils.exceptions import InvalidSyntaxException +from ytdl_sub.script.utils.exceptions import UnreachableSyntaxException from ytdl_sub.script.utils.parser_exception_formatter import ParserExceptionFormatter from ytdl_sub.utils.exceptions import StringFormattingException from ytdl_sub.validators.string_formatter_validators import is_valid_source_variable_name # pylint: disable=invalid-name +UNREACHABLE = UnreachableSyntaxException( + "If you see this error, you have discovered a bug in the script parser!\n" + "Please upload your config/subscription file(s) to and make a GitHub issue at " + "https://github.com/jmbannon/ytdl-sub/issues" +) + UNEXPECTED_ARGUMENT = InvalidSyntaxException("Unexpected comma when parsing arguments") MAP_KEY_WITH_NO_VALUE = InvalidSyntaxException("Map has a key with no value") MAP_KEY_MULTIPLE_VALUES = InvalidSyntaxException( @@ -285,15 +292,15 @@ class _Parser: value_args = self._parse_args(breaking_chars=",}") if len(value_args) == 0: raise MAP_KEY_WITH_NO_VALUE - if len(value_args) > 1: - raise StringFormattingException("map has key with multiple values") if isinstance(key, NonHashable): raise MAP_KEY_NOT_HASHABLE + if len(value_args) > 1: + raise UNREACHABLE output[key] = value_args[0] key = None else: - raise StringFormattingException("Invalid map") + raise UNREACHABLE def _parse(self) -> SyntaxTree: bracket_counter = 0 diff --git a/src/ytdl_sub/script/utils/exceptions.py b/src/ytdl_sub/script/utils/exceptions.py index 2a4df9f9..fffd427a 100644 --- a/src/ytdl_sub/script/utils/exceptions.py +++ b/src/ytdl_sub/script/utils/exceptions.py @@ -3,3 +3,7 @@ from ytdl_sub.utils.exceptions import ValidationException class InvalidSyntaxException(ValidationException): """Syntax is incorrect""" + + +class UnreachableSyntaxException(InvalidSyntaxException): + """For use in places where code _should_ never reach, but might from bugs"""