Skip to content

Commit 470723b

Browse files
committed
fix(robotlangserver): Ignore parsing errors in test discovery
If a file is not valid, i.e. not in UTF-8 format, test discovery does not stop, but an error is written in the output
1 parent 532f5e9 commit 470723b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

robotcode/language_server/robotframework/parts/discovering.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(self, parent: RobotLanguageServerProtocol) -> None:
106106
self._patch()
107107

108108
def _patch(self) -> None:
109-
from robot.api.parsing import get_model
109+
from robot.api.parsing import File, get_model
110110
from robot.running import TestSuite
111111
from robot.running.builder.builders import RobotParser, TestSuiteBuilder
112112

@@ -128,12 +128,24 @@ def get_source(self: Any, source: str) -> str:
128128
orig = RobotParser._build
129129

130130
def my_get_model_v4(source: str, data_only: bool = False, curdir: Optional[str] = None) -> Any:
131-
return get_model(source, data_only, curdir)
131+
try:
132+
return get_model(source, data_only, curdir)
133+
except (SystemExit, KeyboardInterrupt):
134+
raise
135+
except BaseException as e:
136+
self._logger.critical(f"Can't parse {source}: {e}")
137+
return File(source=source)
132138

133139
def my_get_model_v6(
134140
source: str, data_only: bool = False, curdir: Optional[str] = None, lang: Any = None
135141
) -> Any:
136-
return get_model(source, data_only, curdir, lang)
142+
try:
143+
return get_model(source, data_only, curdir, lang)
144+
except (SystemExit, KeyboardInterrupt):
145+
raise
146+
except BaseException as e:
147+
self._logger.critical(f"Can't parse {source}: {e}")
148+
return File(source=source)
137149

138150
my_get_model = my_get_model_v4 if get_robot_version() < (6, 0) else my_get_model_v6
139151

0 commit comments

Comments
 (0)