only single exception type

This commit is contained in:
Jesse Bannon 2023-11-10 09:16:08 -08:00
parent 2fae3929be
commit ed8ab12a3b
3 changed files with 4 additions and 14 deletions

View file

@ -15,7 +15,6 @@ from ytdl_sub.script.types.syntax_tree import SyntaxTree
from ytdl_sub.script.types.variable import FunctionArgument from ytdl_sub.script.types.variable import FunctionArgument
from ytdl_sub.script.types.variable import Variable from ytdl_sub.script.types.variable import Variable
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
from ytdl_sub.script.utils.exceptions import NonFormattedInvalidSyntaxException
from ytdl_sub.script.utils.parser_exception_formatter import ParserExceptionFormatter from ytdl_sub.script.utils.parser_exception_formatter import ParserExceptionFormatter
from ytdl_sub.utils.exceptions import StringFormattingException from ytdl_sub.utils.exceptions import StringFormattingException
from ytdl_sub.validators.string_formatter_validators import is_valid_source_variable_name from ytdl_sub.validators.string_formatter_validators import is_valid_source_variable_name
@ -32,7 +31,7 @@ class _Parser:
try: try:
self._syntax_tree = self._parse() self._syntax_tree = self._parse()
except NonFormattedInvalidSyntaxException as exc: except InvalidSyntaxException as exc:
raise ParserExceptionFormatter( raise ParserExceptionFormatter(
self._text, self._error_highlight_pos, self._pos, exc self._text, self._error_highlight_pos, self._pos, exc
).highlight() from exc ).highlight() from exc
@ -243,7 +242,7 @@ class _Parser:
while ch := self._read(increment_pos=False): while ch := self._read(increment_pos=False):
if ch == "}": if ch == "}":
if key is not None: if key is not None:
raise NonFormattedInvalidSyntaxException("Map has a key with no value") raise InvalidSyntaxException("Map has a key with no value")
self._pos += 1 self._pos += 1
return UnresolvedMap(value=output) return UnresolvedMap(value=output)
@ -268,7 +267,7 @@ class _Parser:
self._pos += 1 self._pos += 1
value_args = self._parse_args(breaking_chars=",}") value_args = self._parse_args(breaking_chars=",}")
if len(value_args) != 1: if len(value_args) != 1:
raise NonFormattedInvalidSyntaxException("Map has a key with no value") raise InvalidSyntaxException("Map has a key with no value")
output[key] = value_args[0] output[key] = value_args[0]
key = None key = None

View file

@ -3,9 +3,3 @@ from ytdl_sub.utils.exceptions import ValidationException
class InvalidSyntaxException(ValidationException): class InvalidSyntaxException(ValidationException):
"""Syntax is incorrect""" """Syntax is incorrect"""
class NonFormattedInvalidSyntaxException(InvalidSyntaxException):
"""
Syntax is incorrect, and the exception itself has not been formatted yet to be user-facing
"""

View file

@ -2,13 +2,10 @@ import sys
from typing import List from typing import List
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
from ytdl_sub.script.utils.exceptions import NonFormattedInvalidSyntaxException
class ParserExceptionFormatter: class ParserExceptionFormatter:
def __init__( def __init__(self, text: str, start: int, end: int, exception: InvalidSyntaxException):
self, text: str, start: int, end: int, exception: NonFormattedInvalidSyntaxException
):
self._text = text self._text = text
self._start = start self._start = start
self._end = end self._end = end