Skip to content

Commit

Permalink
fix(analyzer): corrected exception in parsing ForHeaders with invalid…
Browse files Browse the repository at this point in the history
… variable
  • Loading branch information
d-biehl committed Oct 25, 2024
1 parent f3ecc22 commit 0851d4f
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
ArgumentDefinition,
EnvironmentVariableDefinition,
GlobalVariableDefinition,
InvalidVariableError,
LibraryEntry,
LocalVariableDefinition,
TestVariableDefinition,
Expand Down Expand Up @@ -1185,7 +1186,7 @@ def _visit_Arguments(self, node: Statement) -> None: # noqa: N802
)
)

except VariableError:
except (VariableError, InvalidVariableError):
pass

def _analyze_assign_statement(self, node: Statement) -> None:
Expand Down Expand Up @@ -1225,7 +1226,7 @@ def _analyze_assign_statement(self, node: Statement) -> None:
)
)

except VariableError:
except (VariableError, InvalidVariableError):
pass

def visit_InlineIfHeader(self, node: Statement) -> None: # noqa: N802
Expand All @@ -1239,7 +1240,7 @@ def visit_ForHeader(self, node: Statement) -> None: # noqa: N802
variables = node.get_tokens(Token.VARIABLE)
for variable in variables:
variable_token = self._get_variable_token(variable)
if variable_token is not None:
if variable_token is not None and is_variable(variable_token.value):
existing_var = self._find_variable(variable_token.value)

if existing_var is None or existing_var.type not in [
Expand Down Expand Up @@ -1301,7 +1302,7 @@ def visit_ExceptHeader(self, node: Statement) -> None: # noqa: N802
source=self._namespace.source,
)

except VariableError:
except (VariableError, InvalidVariableError):
pass

def _format_template(self, template: str, arguments: Tuple[str, ...]) -> Tuple[str, Tuple[str, ...]]:
Expand Down Expand Up @@ -1615,9 +1616,12 @@ def _find_variable(self, name: str) -> Optional[VariableDefinition]:
else self._suite_variables if self._in_setting else self._variables
)

matcher = VariableMatcher(name)
try:
matcher = VariableMatcher(name)

return vars.get(matcher, None)
return vars.get(matcher, None)
except (VariableError, InvalidVariableError):
return None

def _is_number(self, name: str) -> bool:
if name.startswith("$"):
Expand Down

0 comments on commit 0851d4f

Please sign in to comment.