Skip to content

Commit e03564f

Browse files
committed
correct handling of errors occurred in loading files wich contains errors (like encoding) in finding references
1 parent ef99517 commit e03564f

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

robotcode/language_server/robotframework/diagnostics/imports_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ async def _get_libdoc() -> LibraryDoc:
755755

756756
if result.stdout:
757757
self._logger.warning(lambda: f"stdout captured at loading library {name}{repr(args)}:\n{result.stdout}")
758+
758759
return result
759760

760761
entry_key = _LibrariesEntryKey(source, args)

robotcode/language_server/robotframework/parts/references.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,22 @@ async def _find_references(
134134
ignore_patterns=config.exclude_patterns or [], # type: ignore
135135
absolute=True,
136136
):
137-
doc = await self.parent.robot_workspace.get_or_open_document(f, "robotframework")
137+
try:
138+
doc = await self.parent.robot_workspace.get_or_open_document(f, "robotframework")
139+
except (SystemExit, KeyboardInterrupt, asyncio.CancelledError):
140+
raise
141+
except BaseException as ex:
142+
self._logger.exception(ex)
143+
else:
144+
futures.append(run_coroutine_in_thread(func, doc, *args, **kwargs))
138145

139-
futures.append(run_coroutine_in_thread(func, doc, *args, **kwargs))
140146
for e in await asyncio.gather(*futures, return_exceptions=True):
141147
if isinstance(e, BaseException):
142148
if not isinstance(result, asyncio.CancelledError):
143149
self._logger.exception(e)
144150
continue
145151
result.extend(e)
152+
146153
return result
147154

148155
async def _references_default(
@@ -501,18 +508,25 @@ async def find_keyword_references_in_file(
501508
lib_doc: Optional[LibraryDoc] = None,
502509
) -> List[Location]:
503510

504-
namespace = await self.parent.documents_cache.get_namespace(doc)
511+
try:
512+
namespace = await self.parent.documents_cache.get_namespace(doc)
505513

506-
if (
507-
lib_doc is not None
508-
and lib_doc.source is not None
509-
and lib_doc.source != str(doc.uri.to_path())
510-
and lib_doc not in (e.library_doc for e in (await namespace.get_libraries()).values())
511-
and lib_doc not in (e.library_doc for e in (await namespace.get_resources()).values())
512-
):
513-
return []
514+
if (
515+
lib_doc is not None
516+
and lib_doc.source is not None
517+
and lib_doc.source != str(doc.uri.to_path())
518+
and lib_doc not in (e.library_doc for e in (await namespace.get_libraries()).values())
519+
and lib_doc not in (e.library_doc for e in (await namespace.get_resources()).values())
520+
):
521+
return []
522+
523+
return await self._find_keyword_references_in_namespace(namespace, kw_doc)
524+
except (SystemExit, KeyboardInterrupt, asyncio.CancelledError):
525+
raise
526+
except BaseException as e:
527+
self._logger.exception(e)
514528

515-
return await self._find_keyword_references_in_namespace(namespace, kw_doc)
529+
return []
516530

517531
async def _find_keyword_references_in_namespace(self, namespace: Namespace, kw_doc: KeywordDoc) -> List[Location]:
518532
from robot.parsing.lexer.tokens import Token as RobotToken

0 commit comments

Comments
 (0)