[BACKEND] Improve variable validation
This commit is contained in:
parent
5d1fd0d7c6
commit
a291d3abb4
2 changed files with 24 additions and 10 deletions
|
|
@ -11,7 +11,8 @@ from ytdl_sub.entries.variables.override_variables import SUBSCRIPTION_NAME
|
|||
from ytdl_sub.entries.variables.override_variables import OverrideVariables
|
||||
from ytdl_sub.script.parser import parse
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.utils.exceptions import InvalidVariableNameException
|
||||
from ytdl_sub.script.utils.exceptions import ScriptVariableNotResolved
|
||||
from ytdl_sub.utils.exceptions import InvalidVariableNameException, StringFormattingException
|
||||
from ytdl_sub.utils.exceptions import ValidationException
|
||||
from ytdl_sub.utils.script import ScriptUtils
|
||||
from ytdl_sub.utils.scriptable import Scriptable
|
||||
|
|
@ -177,11 +178,19 @@ class Overrides(DictFormatterValidator, Scriptable):
|
|||
script = entry.script
|
||||
unresolvable = entry.unresolvable
|
||||
|
||||
return formatter.post_process(
|
||||
str(
|
||||
script.resolve_once(
|
||||
dict({"tmp_var": formatter.format_string}, **(function_overrides or {})),
|
||||
unresolvable=unresolvable,
|
||||
)["tmp_var"]
|
||||
try:
|
||||
return formatter.post_process(
|
||||
str(
|
||||
script.resolve_once(
|
||||
dict({"tmp_var": formatter.format_string}, **(function_overrides or {})),
|
||||
unresolvable=unresolvable,
|
||||
)["tmp_var"]
|
||||
)
|
||||
)
|
||||
)
|
||||
except ScriptVariableNotResolved as exc:
|
||||
raise StringFormattingException(
|
||||
"Tried to resolve the following script, but could not due to unresolved "
|
||||
f"variables:\n {formatter.format_string}\n"
|
||||
"This is most likely due to circular dependencies in variables. "
|
||||
"If you think otherwise, please file a bug on GitHub and post your config. Thanks!"
|
||||
) from exc
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from ytdl_sub.script.types.resolvable import Lambda
|
|||
from ytdl_sub.script.types.resolvable import Resolvable
|
||||
from ytdl_sub.script.types.syntax_tree import SyntaxTree
|
||||
from ytdl_sub.script.types.variable import Variable
|
||||
from ytdl_sub.script.utils.exceptions import UNREACHABLE
|
||||
from ytdl_sub.script.utils.exceptions import UNREACHABLE, ScriptVariableNotResolved
|
||||
from ytdl_sub.script.utils.exceptions import CycleDetected
|
||||
from ytdl_sub.script.utils.exceptions import IncompatibleFunctionArguments
|
||||
from ytdl_sub.script.utils.exceptions import InvalidCustomFunctionArguments
|
||||
|
|
@ -269,6 +269,11 @@ class Script:
|
|||
Returns
|
||||
-------
|
||||
Dict of resolved values
|
||||
|
||||
Raises
|
||||
------
|
||||
ScriptVariableNotResolved
|
||||
If specifying a filter of variable to resolve, and one of them does not.
|
||||
"""
|
||||
resolved: Dict[Variable, Resolvable] = {
|
||||
Variable(name): value for name, value in (pre_resolved or {}).items()
|
||||
|
|
@ -322,7 +327,7 @@ class Script:
|
|||
if output_filter:
|
||||
for name in output_filter:
|
||||
if name not in resolved_variables:
|
||||
raise ValueError(f"Specified {name} to resolve, but it did not")
|
||||
raise ScriptVariableNotResolved(f"Specified {name} to resolve, but it did not")
|
||||
|
||||
return ScriptOutput(
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue