Skip to content

Commit eab71f8

Browse files
committed
fix(robotlangserver): Loading documents hardened
Invalid document don't break loading, initializing and analysing documents and discovering tests
1 parent 60d76aa commit eab71f8

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

robotcode/language_server/robotframework/diagnostics/imports_manager.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,11 @@ async def check_file_changed(self, changes: List[FileEvent]) -> Optional[FileCha
424424
continue
425425

426426
path = uri.to_path()
427-
if self._lib_doc.source and path.resolve().samefile(Path(self._lib_doc.source).resolve()):
427+
if (
428+
self._lib_doc.source
429+
and path.exists()
430+
and path.resolve().samefile(Path(self._lib_doc.source).resolve())
431+
):
428432
await self._invalidate()
429433

430434
return change.type

robotcode/language_server/robotframework/parts/robot_workspace.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,27 @@ async def _load_workspace_documents(self, sender: Any) -> List[WorkspaceDocument
100100
async with self.parent.window.progress(
101101
"Load workspace", cancellable=True, current=0, max=len(files), start=False
102102
) as progress:
103-
for i, f in enumerate(files):
104-
await self.parent.documents.get_or_open_document(f, "robotframework")
105-
106-
if config.analysis.progress_mode != AnalysisProgressMode.OFF:
107-
name = f.relative_to(folder.uri.to_path())
108-
109-
progress.begin()
110-
progress.report(
111-
f"Load {str(name)}"
112-
if config.analysis.progress_mode == AnalysisProgressMode.DETAILED
113-
else None,
114-
current=i,
115-
)
116-
117-
self.documents_loaded.set()
103+
try:
104+
for i, f in enumerate(files):
105+
try:
106+
await self.parent.documents.get_or_open_document(f, "robotframework")
107+
108+
if config.analysis.progress_mode != AnalysisProgressMode.OFF:
109+
name = f.relative_to(folder.uri.to_path())
110+
111+
progress.begin()
112+
progress.report(
113+
f"Load {str(name)}"
114+
if config.analysis.progress_mode == AnalysisProgressMode.DETAILED
115+
else None,
116+
current=i,
117+
)
118+
except (SystemExit, KeyboardInterrupt):
119+
raise
120+
except BaseException as e:
121+
self._logger.critical(f"Can't load document {f}: {e}")
122+
finally:
123+
self.documents_loaded.set()
118124

119125
for i, f in enumerate(files):
120126
try:
@@ -154,7 +160,7 @@ async def _load_workspace_documents(self, sender: Any) -> List[WorkspaceDocument
154160
except (SystemExit, KeyboardInterrupt, asyncio.CancelledError):
155161
raise
156162
except BaseException as e:
157-
self._logger.exception(e)
163+
self._logger.critical(f"Can't initialize document {f}: {e}")
158164

159165
if canceled:
160166
return []

0 commit comments

Comments
 (0)