allow user errors for non static

This commit is contained in:
Jesse Bannon 2025-12-27 14:06:37 -08:00
parent 4b7d6ae12b
commit af527bd2ef
2 changed files with 20 additions and 7 deletions

View file

@ -16,6 +16,7 @@ from ytdl_sub.downloaders.url.validators import MultiUrlValidator
from ytdl_sub.entries.variables.override_variables import REQUIRED_OVERRIDE_VARIABLE_NAMES from ytdl_sub.entries.variables.override_variables import REQUIRED_OVERRIDE_VARIABLE_NAMES
from ytdl_sub.script.script import Script from ytdl_sub.script.script import Script
from ytdl_sub.script.script import _is_function from ytdl_sub.script.script import _is_function
from ytdl_sub.script.utils.exceptions import RuntimeException
from ytdl_sub.utils.scriptable import BASE_SCRIPT from ytdl_sub.utils.scriptable import BASE_SCRIPT
from ytdl_sub.validators.string_formatter_validators import to_variable_dependency_format_string from ytdl_sub.validators.string_formatter_validators import to_variable_dependency_format_string
from ytdl_sub.validators.string_formatter_validators import validate_formatters from ytdl_sub.validators.string_formatter_validators import validate_formatters
@ -44,15 +45,21 @@ def _add_dummy_variables(variables: Iterable[str]) -> Dict[str, str]:
def _add_dummy_overrides(overrides: Overrides) -> Dict[str, str]: def _add_dummy_overrides(overrides: Overrides) -> Dict[str, str]:
# Have the dummy override variable contain all variable deps that it uses in the string # Have the dummy override variable contain all variable deps that it uses in the string
dummy_overrides: Dict[str, str] = {} dummy_overrides: Dict[str, str] = {}
for override_name in _override_variables(overrides): for override_name, format_string in overrides.dict_with_format_strings.items():
if _is_function(override_name): if _is_function(override_name):
continue continue
# pylint: disable=protected-access try:
dummy_overrides[override_name] = to_variable_dependency_format_string( # Attempt to get the resolved version, which will only happen
script=overrides.script, parsed_format_string=overrides.script._variables[override_name] # if it does not have any dependencies to the entry
) value = overrides.script.get(override_name).native
# pylint: enable=protected-access except RuntimeException:
value = to_variable_dependency_format_string(
script=overrides.script, parsed_format_string=overrides.script._variables[override_name]
)
dummy_overrides[override_name] = value
return dummy_overrides return dummy_overrides

View file

@ -8,7 +8,7 @@ from ytdl_sub.entries.script.variable_definitions import VARIABLES
from ytdl_sub.script.parser import parse from ytdl_sub.script.parser import parse
from ytdl_sub.script.script import Script from ytdl_sub.script.script import Script
from ytdl_sub.script.types.syntax_tree import SyntaxTree from ytdl_sub.script.types.syntax_tree import SyntaxTree
from ytdl_sub.script.utils.exceptions import RuntimeException from ytdl_sub.script.utils.exceptions import RuntimeException, UserThrownRuntimeError
from ytdl_sub.script.utils.exceptions import ScriptVariableNotResolved from ytdl_sub.script.utils.exceptions import ScriptVariableNotResolved
from ytdl_sub.script.utils.exceptions import UserException from ytdl_sub.script.utils.exceptions import UserException
from ytdl_sub.utils.exceptions import StringFormattingVariableNotFoundException from ytdl_sub.utils.exceptions import StringFormattingVariableNotFoundException
@ -255,6 +255,12 @@ def _validate_formatter(
"entry variables" "entry variables"
) from exc ) from exc
raise StringFormattingVariableNotFoundException(exc) from exc raise StringFormattingVariableNotFoundException(exc) from exc
except UserThrownRuntimeError as exc:
# Errors are expected for non-static formatters due to missing entry
# data. Raise otherwise.
if not is_static_formatter:
return formatter_validator.format_string
raise exc
def validate_formatters( def validate_formatters(