Skip to content

Commit 0851d4f

Browse files
committed
fix(analyzer): corrected exception in parsing ForHeaders with invalid variable
1 parent f3ecc22 commit 0851d4f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Diff for: packages/robot/src/robotcode/robot/diagnostics/namespace_analyzer.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
ArgumentDefinition,
6060
EnvironmentVariableDefinition,
6161
GlobalVariableDefinition,
62+
InvalidVariableError,
6263
LibraryEntry,
6364
LocalVariableDefinition,
6465
TestVariableDefinition,
@@ -1185,7 +1186,7 @@ def _visit_Arguments(self, node: Statement) -> None: # noqa: N802
11851186
)
11861187
)
11871188

1188-
except VariableError:
1189+
except (VariableError, InvalidVariableError):
11891190
pass
11901191

11911192
def _analyze_assign_statement(self, node: Statement) -> None:
@@ -1225,7 +1226,7 @@ def _analyze_assign_statement(self, node: Statement) -> None:
12251226
)
12261227
)
12271228

1228-
except VariableError:
1229+
except (VariableError, InvalidVariableError):
12291230
pass
12301231

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

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

1304-
except VariableError:
1305+
except (VariableError, InvalidVariableError):
13051306
pass
13061307

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

1618-
matcher = VariableMatcher(name)
1619+
try:
1620+
matcher = VariableMatcher(name)
16191621

1620-
return vars.get(matcher, None)
1622+
return vars.get(matcher, None)
1623+
except (VariableError, InvalidVariableError):
1624+
return None
16211625

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

0 commit comments

Comments
 (0)