robotcode-robot 2.9.0.dev230__py3-none-any.whl → 2.9.0.dev264__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- __version__ = "2.9.0-dev.230"
1
+ __version__ = "2.9.0-dev.264"
@@ -127,7 +127,8 @@ class Expression:
127
127
  expr: str = field(
128
128
  description="""\
129
129
  Expression to evaluate. This must be a Python "eval" expression.
130
- For security reasons, only certain expressions and functions are allowed.
130
+ Only certain names are available, to keep expressions simple queries.
131
+ This is not a sandbox: like the rest of the project, the configuration must come from a trusted source.
131
132
 
132
133
  Examples:
133
134
  ```toml
@@ -180,7 +181,8 @@ class Condition:
180
181
  if_: str = field(
181
182
  description="""\
182
183
  Condition to evaluate. This must be a Python "eval" expression.
183
- For security reasons, only certain expressions and functions are allowed.
184
+ Only certain names are available, to keep expressions simple queries.
185
+ This is not a sandbox: like the rest of the project, the configuration must come from a trusted source.
184
186
 
185
187
  Examples:
186
188
  ```toml
@@ -41,7 +41,7 @@ from ..utils import RF_VERSION
41
41
  from ..utils.markdown_blocks import RobotBlock, find_robot_blocks, read_markdown_data
42
42
  from ..utils.stubs import Languages
43
43
  from .data_cache import CacheSection
44
- from .imports_manager import ImportsManager, NamespaceMetaData
44
+ from .imports_manager import ImportsManager, NamespaceMetaData, model_doc_cache_source
45
45
  from .library_doc import LibraryDoc
46
46
  from .namespace import (
47
47
  DocumentType,
@@ -727,7 +727,7 @@ class DocumentsCacheHelper:
727
727
  try:
728
728
  for section, source_of in (
729
729
  (CacheSection.NAMESPACE, _namespace_cache_source),
730
- (CacheSection.RESOURCE, str),
730
+ (CacheSection.RESOURCE, model_doc_cache_source),
731
731
  ):
732
732
  missing = [
733
733
  entry.entry_name
@@ -737,7 +737,7 @@ class DocumentsCacheHelper:
737
737
  if not missing:
738
738
  continue
739
739
  if section == CacheSection.RESOURCE:
740
- imports_manager.remove_cached_resource_docs(missing)
740
+ imports_manager.remove_cached_resource_docs(sorted({model_doc_cache_source(m) for m in missing}))
741
741
  else:
742
742
  data_cache.remove_entries(section, missing)
743
743
  except (SystemExit, KeyboardInterrupt):
@@ -26,6 +26,12 @@ class Error:
26
26
  VARIABLES_TIMEOUT_ERROR = "VariablesTimeoutError"
27
27
  LIBRARY_EXIT_ERROR = "LibraryExitError"
28
28
  VARIABLES_EXIT_ERROR = "VariablesExitError"
29
+ LIBRARY_NOT_FOUND = "LibraryNotFound"
30
+ RESOURCE_NOT_FOUND = "ResourceNotFound"
31
+ VARIABLES_NOT_FOUND = "VariablesNotFound"
32
+ LIBRARY_IMPORT_FAILED = "LibraryImportFailed"
33
+ RESOURCE_IMPORT_FAILED = "ResourceImportFailed"
34
+ VARIABLES_IMPORT_FAILED = "VariablesImportFailed"
29
35
  DEPRECATED_KEYWORD = "DeprecatedKeyword"
30
36
  KEYWORD_CONTAINS_ERRORS = "KeywordContainsErrors"
31
37
  RESERVED_KEYWORD = "ReservedKeyword"
@@ -13,6 +13,7 @@ from dataclasses import dataclass, field
13
13
  from pathlib import Path
14
14
  from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
15
15
 
16
+ from robot.errors import DataError
16
17
  from robotcode.core.lsp.types import (
17
18
  Diagnostic,
18
19
  DiagnosticRelatedInformation,
@@ -23,9 +24,10 @@ from robotcode.core.lsp.types import (
23
24
  )
24
25
  from robotcode.core.uri import Uri
25
26
  from robotcode.core.utils.logging import LoggingDescriptor
26
- from robotcode.core.utils.path import file_id, same_file_id
27
+ from robotcode.core.utils.path import file_id, normalized_path, same_file_id
27
28
 
28
29
  from ..utils import RF_VERSION
30
+ from ..utils.robot_path import ImportNotFoundError
29
31
  from .entities import (
30
32
  Import,
31
33
  LibraryEntry,
@@ -60,18 +62,47 @@ class _NameSpaceError(Exception):
60
62
  pass
61
63
 
62
64
 
65
+ _ROBOTCODE_CODES = frozenset(value for name, value in vars(Error).items() if name.isupper() and isinstance(value, str))
66
+
67
+ _NOT_FOUND_CODES = {
68
+ LibraryImport: Error.LIBRARY_NOT_FOUND,
69
+ ResourceImport: Error.RESOURCE_NOT_FOUND,
70
+ VariablesImport: Error.VARIABLES_NOT_FOUND,
71
+ }
72
+
73
+ _IMPORT_FAILED_CODES = {
74
+ LibraryImport: Error.LIBRARY_IMPORT_FAILED,
75
+ ResourceImport: Error.RESOURCE_IMPORT_FAILED,
76
+ VariablesImport: Error.VARIABLES_IMPORT_FAILED,
77
+ }
78
+
79
+
80
+ def _failed_import_code(imp: Import, code: str, not_found: bool = False) -> str:
81
+ """The code of a failed import whose error has `code`: an exception's class name or one of RobotCode's codes."""
82
+ if not_found:
83
+ return _NOT_FOUND_CODES.get(type(imp), code)
84
+ if code in _ROBOTCODE_CODES:
85
+ return code
86
+ return _IMPORT_FAILED_CODES.get(type(imp), code)
87
+
88
+
63
89
  @dataclass(frozen=True, slots=True)
64
90
  class FailedImport:
65
91
  """An import whose resolution raised or whose library or variables documentation has errors.
66
92
 
67
93
  `base_dir` and `variables` are what its file or module was looked up with.
68
- `found` tells whether that lookup succeeded, so that only loading failed.
94
+ `source` is the normalized path that lookup found, or `None` when it found nothing.
69
95
  """
70
96
 
71
97
  imp: Import
72
98
  base_dir: str
73
99
  variables: Dict[str, Any]
74
- found: bool
100
+ source: Optional[str]
101
+
102
+ @property
103
+ def found(self) -> bool:
104
+ """Whether the lookup found the file or module, so that only loading failed."""
105
+ return self.source is not None
75
106
 
76
107
 
77
108
  @dataclass(frozen=True, slots=True)
@@ -186,8 +217,10 @@ class ImportResolver:
186
217
 
187
218
  def _record_failed_import(self, imp: Import, base_dir: str) -> None:
188
219
  # _refresh_variables replaces the dict, so the import keeps the variables it was resolved with
189
- found = self._imports_manager.find_import_source(imp, base_dir, self._variables) is not None
190
- self._failed_imports.append(FailedImport(imp, base_dir, self._variables, found))
220
+ found = self._imports_manager.find_import_source(imp, base_dir, self._variables)
221
+ self._failed_imports.append(
222
+ FailedImport(imp, base_dir, self._variables, str(normalized_path(found)) if found is not None else None)
223
+ )
191
224
 
192
225
  def _append_diagnostics(
193
226
  self,
@@ -346,7 +379,7 @@ class ImportResolver:
346
379
  message=str(e),
347
380
  severity=DiagnosticSeverity.ERROR,
348
381
  source=DIAGNOSTICS_SOURCE_NAME,
349
- code=type(e).__qualname__,
382
+ code=_failed_import_code(imp, type(e).__qualname__, isinstance(e, ImportNotFoundError)),
350
383
  )
351
384
  elif parent_import is not None:
352
385
  self._append_diagnostics(
@@ -591,6 +624,14 @@ class ImportResolver:
591
624
  )
592
625
  return
593
626
 
627
+ # Robot Framework refuses the file: the import keeps its entry for navigation, but nothing of the file
628
+ # reaches the scope or the keyword lookup
629
+ if resource_doc.import_error is not None:
630
+ entry.import_range = imp.range
631
+ entry.import_source = imp.source
632
+ self._import_entries[imp] = entry
633
+ raise DataError(resource_doc.import_error.message)
634
+
594
635
  # Already imported check
595
636
  already_imported = next(
596
637
  (
@@ -784,7 +825,7 @@ class ImportResolver:
784
825
  message=err.message,
785
826
  severity=DiagnosticSeverity.ERROR,
786
827
  source=DIAGNOSTICS_SOURCE_NAME,
787
- code=err.type_name,
828
+ code=_failed_import_code(imp, err.type_name),
788
829
  )
789
830
  elif entry.library_doc.errors is not None:
790
831
  for err in entry.library_doc.errors:
@@ -793,7 +834,7 @@ class ImportResolver:
793
834
  message=err.message,
794
835
  severity=DiagnosticSeverity.ERROR,
795
836
  source=DIAGNOSTICS_SOURCE_NAME,
796
- code=err.type_name,
837
+ code=_failed_import_code(imp, err.type_name),
797
838
  )
798
839
 
799
840
  if entry.library_doc.loaded_without_arguments:
@@ -58,7 +58,7 @@ from robotcode.core.utils.path import (
58
58
  from ..__version__ import __version__
59
59
  from ..language_definitions import ROBOT_LANGUAGE_IDS
60
60
  from ..utils import RF_VERSION
61
- from ..utils.robot_path import find_file_ex
61
+ from ..utils.robot_path import ImportNotFoundError, find_file_ex
62
62
  from ..utils.stubs import Languages
63
63
  from ..utils.variables import contains_variable, environment_value_hash
64
64
  from .data_cache import CACHE_DIR_NAME, CacheSection, build_cache_dir
@@ -588,6 +588,16 @@ class _VariablesEntry(_ImportEntry):
588
588
  return self.get_libdoc_with_meta()[0]
589
589
 
590
590
 
591
+ def _model_doc_cache_key(source: str, suite_model: bool) -> str:
592
+ """The key of a model doc: a doc built from a suite model has its own, see `get_libdoc_from_model`."""
593
+ return f"{source}\nsuite" if suite_model else source
594
+
595
+
596
+ def model_doc_cache_source(entry_name: str) -> str:
597
+ """The source of a model doc entry in the disk cache, see `_model_doc_cache_key`."""
598
+ return entry_name.split("\n", 1)[0]
599
+
600
+
591
601
  @dataclass(slots=True)
592
602
  class LibraryMetaData:
593
603
  name: Optional[str]
@@ -598,7 +608,9 @@ class LibraryMetaData:
598
608
 
599
609
  file_infos: Optional[Dict[str, DiskInfo]] = None
600
610
 
601
- has_errors: bool = False
611
+ # not compared: a failed load of the same file must not make a stored namespace look outdated;
612
+ # the cache reads check it explicitly
613
+ has_errors: bool = field(default=False, compare=False)
602
614
 
603
615
  @property
604
616
  def cache_key(self) -> str:
@@ -1137,9 +1149,10 @@ class ImportsManager:
1137
1149
 
1138
1150
  ``sources`` are normalized paths, as the entries of the cache name them.
1139
1151
  """
1140
- for source in sources:
1141
- self._model_docs_by_source.pop(source, None)
1142
- self.data_cache.remove_entries(CacheSection.RESOURCE, sources)
1152
+ keys = [_model_doc_cache_key(source, suite_model) for source in sources for suite_model in (False, True)]
1153
+ for key in keys:
1154
+ self._model_docs_by_source.pop(key, None)
1155
+ self.data_cache.remove_entries(CacheSection.RESOURCE, keys)
1143
1156
 
1144
1157
  @_logger.call
1145
1158
  def get_command_line_variables(self) -> List[VariableDefinition]:
@@ -1223,7 +1236,11 @@ class ImportsManager:
1223
1236
  Range.zero(),
1224
1237
  f"Error in command line variable file '{name}({', '.join(args)})': {e}",
1225
1238
  DiagnosticSeverity.ERROR,
1226
- type(e).__name__,
1239
+ (
1240
+ DiagnosticError.VARIABLES_NOT_FOUND
1241
+ if isinstance(e, ImportNotFoundError)
1242
+ else type(e).__name__
1243
+ ),
1227
1244
  )
1228
1245
  )
1229
1246
  except (SystemExit, KeyboardInterrupt):
@@ -1901,7 +1918,9 @@ class ImportsManager:
1901
1918
  if entry is not None and entry.meta is not None:
1902
1919
  if entry.meta.has_errors:
1903
1920
  self._logger.debug(
1904
- lambda: f"Saved library spec for {name}{args!r} is not used due to errors in meta data",
1921
+ lambda: (
1922
+ f"Saved library spec for {name}{args!r} is not used because its load reported errors"
1923
+ ),
1905
1924
  context_name="import",
1906
1925
  )
1907
1926
  elif entry.meta == meta:
@@ -2016,6 +2035,8 @@ class ImportsManager:
2016
2035
  model: ast.AST,
2017
2036
  source: str,
2018
2037
  meta: Optional[RobotFileMeta] = None,
2038
+ *,
2039
+ suite_model: bool = False,
2019
2040
  ) -> ResourceDoc:
2020
2041
  """Build (or load from cache) the ResourceDoc for a parsed model.
2021
2042
 
@@ -2031,10 +2052,10 @@ class ImportsManager:
2031
2052
  return entry[source]
2032
2053
 
2033
2054
  if meta is not None and meta.trusted:
2034
- result = self._get_model_doc_cached(source, meta)
2055
+ result = self._get_model_doc_cached(source, meta, suite_model)
2035
2056
  if result is None:
2036
2057
  result = get_model_doc(model=model, source=source)
2037
- self._save_model_doc_cache(source, result, meta)
2058
+ self._save_model_doc_cache(source, result, meta, suite_model)
2038
2059
  else:
2039
2060
  result = get_model_doc(model=model, source=source)
2040
2061
 
@@ -2054,16 +2075,19 @@ class ImportsManager:
2054
2075
  return None
2055
2076
  return RobotFileMeta(normalized, info)
2056
2077
 
2057
- def _get_model_doc_cached(self, source: str, meta: RobotFileMeta) -> Optional[ResourceDoc]:
2058
- known = self._model_docs_by_source.get(meta.source)
2078
+ def _get_model_doc_cached(
2079
+ self, source: str, meta: RobotFileMeta, suite_model: bool = False
2080
+ ) -> Optional[ResourceDoc]:
2081
+ key = _model_doc_cache_key(meta.source, suite_model)
2082
+ known = self._model_docs_by_source.get(key)
2059
2083
  if known is not None and known[0] == meta:
2060
2084
  return known[1]
2061
2085
 
2062
2086
  try:
2063
- entry = self.data_cache.read_entry(CacheSection.RESOURCE, meta.source, RobotFileMeta, ResourceDoc)
2087
+ entry = self.data_cache.read_entry(CacheSection.RESOURCE, key, RobotFileMeta, ResourceDoc)
2064
2088
  # a doc read with other language settings would hold what the file defines under those settings
2065
2089
  if entry is not None and entry.meta == replace(meta, languages=self._languages_fingerprint):
2066
- self._model_docs_by_source[meta.source] = (meta, entry.data)
2090
+ self._model_docs_by_source[key] = (meta, entry.data)
2067
2091
  return entry.data
2068
2092
  except (SystemExit, KeyboardInterrupt):
2069
2093
  raise
@@ -2076,12 +2100,15 @@ class ImportsManager:
2076
2100
 
2077
2101
  return None
2078
2102
 
2079
- def _save_model_doc_cache(self, source: str, result: ResourceDoc, meta: "RobotFileMeta") -> None:
2080
- self._model_docs_by_source[meta.source] = (meta, result)
2103
+ def _save_model_doc_cache(
2104
+ self, source: str, result: ResourceDoc, meta: "RobotFileMeta", suite_model: bool = False
2105
+ ) -> None:
2106
+ key = _model_doc_cache_key(meta.source, suite_model)
2107
+ self._model_docs_by_source[key] = (meta, result)
2081
2108
 
2082
2109
  try:
2083
2110
  self.data_cache.save_entry(
2084
- CacheSection.RESOURCE, meta.source, replace(meta, languages=self._languages_fingerprint), result
2111
+ CacheSection.RESOURCE, key, replace(meta, languages=self._languages_fingerprint), result
2085
2112
  )
2086
2113
  except (SystemExit, KeyboardInterrupt):
2087
2114
  raise
@@ -2115,8 +2142,16 @@ class ImportsManager:
2115
2142
  entry = self.data_cache.read_entry(
2116
2143
  CacheSection.VARIABLES, meta.cache_key_for_args(args), LibraryMetaData, VariablesDoc
2117
2144
  )
2118
- if entry is not None and entry.meta == meta:
2119
- return entry.data, meta
2145
+ if entry is not None and entry.meta is not None:
2146
+ if entry.meta.has_errors:
2147
+ self._logger.debug(
2148
+ lambda: (
2149
+ f"Saved variables spec for {name}{args!r} is not used because its load reported errors"
2150
+ ),
2151
+ context_name="import",
2152
+ )
2153
+ elif entry.meta == meta:
2154
+ return entry.data, meta
2120
2155
  except (SystemExit, KeyboardInterrupt):
2121
2156
  raise
2122
2157
  except BaseException as e:
@@ -2157,6 +2192,9 @@ class ImportsManager:
2157
2192
  None,
2158
2193
  )
2159
2194
 
2195
+ if meta is not None:
2196
+ meta.has_errors = bool(result.errors)
2197
+
2160
2198
  self._save_import_cache(CacheSection.VARIABLES, meta, result, "variables", name, args)
2161
2199
 
2162
2200
  return result, meta
@@ -16,6 +16,7 @@ from contextlib import contextmanager
16
16
  from dataclasses import MISSING, dataclass, field, fields
17
17
  from enum import Enum
18
18
  from pathlib import Path
19
+ from types import ModuleType
19
20
  from typing import (
20
21
  AbstractSet,
21
22
  Any,
@@ -107,6 +108,7 @@ from ..utils.markdown_docs import (
107
108
  from ..utils.markdownformatter import MarkDownFormatter, NameLinker
108
109
  from ..utils.match import normalize, normalize_namespace
109
110
  from ..utils.robot_patching import patch_variable_not_found
111
+ from ..utils.robot_path import ImportNotFoundError
110
112
  from ..utils.variables import contains_variable, replace_curdir_in_variable_values, search_variable
111
113
  from .entities import (
112
114
  ArgumentDefinition,
@@ -120,6 +122,7 @@ from .entities import (
120
122
  VariableDefinition,
121
123
  VariablesImport,
122
124
  )
125
+ from .errors import Error as DiagnosticError
123
126
 
124
127
  if RF_VERSION < (7, 0):
125
128
  from robot.running.handlers import _PythonHandler, _PythonInitHandler # pyright: ignore[reportMissingImports]
@@ -2264,6 +2267,8 @@ class ResourceDoc(LibraryDoc):
2264
2267
 
2265
2268
  resource_imports: List[Import] = field(default_factory=list, compare=False)
2266
2269
  resource_variables: List[VariableDefinition] = field(default_factory=list, compare=False)
2270
+ # why Robot Framework refuses to import the file as a resource; not in `errors`, which the file reports itself
2271
+ import_error: Optional[Error] = field(default=None, compare=False)
2267
2272
 
2268
2273
 
2269
2274
  @functools.lru_cache(maxsize=1024)
@@ -2693,6 +2698,50 @@ class IgnoreEasterEggLibraryWarning(Exception): # noqa: N818
2693
2698
  pass
2694
2699
 
2695
2700
 
2701
+ def _find_import_file(name: str, base_dir: str, file_type: str) -> str:
2702
+ try:
2703
+ return cast(str, robot_find_file(name, base_dir or ".", file_type))
2704
+ except DataError as e:
2705
+ raise ImportNotFoundError(str(e)) from e
2706
+
2707
+
2708
+ def _mark_not_found(error: Error, exception: BaseException, import_name: str, code: str) -> Error:
2709
+ """Give `error` the code `code` when the import's file, or the module imported by name, was not found.
2710
+
2711
+ `ImportNotFoundError` comes from the lookup of a variable file; a library's file is looked up before the
2712
+ load. Robot Framework's `Importer` raises its `DataError` while handling the original exception, so that
2713
+ exception is the first link of the `__context__` chain that isn't a `DataError`. A missing module of
2714
+ another name is a dependency of the imported file and keeps the error as it is. For `module.Name`, the
2715
+ `Importer` takes `Name` from the module with `getattr`, so a name the module doesn't contain is an
2716
+ `AttributeError` on that module.
2717
+ """
2718
+ cause: Optional[BaseException] = exception
2719
+ seen: Set[int] = set()
2720
+ while isinstance(cause, DataError) and id(cause) not in seen:
2721
+ seen.add(id(cause))
2722
+ cause = cause.__context__
2723
+ module_name, _, member_name = import_name.rpartition(".")
2724
+ if (
2725
+ isinstance(exception, ImportNotFoundError)
2726
+ or (
2727
+ isinstance(cause, ModuleNotFoundError)
2728
+ and cause.name is not None
2729
+ and (import_name == cause.name or import_name.startswith(cause.name + "."))
2730
+ )
2731
+ or (
2732
+ isinstance(cause, AttributeError)
2733
+ and isinstance(cause.obj, ModuleType)
2734
+ and cause.obj.__name__ == module_name
2735
+ and cause.name == member_name
2736
+ )
2737
+ ):
2738
+ error.type_name = code
2739
+ # the import's name is wrong, not the file of the module the error would otherwise point to
2740
+ error.source = None
2741
+ error.line_no = None
2742
+ return error
2743
+
2744
+
2696
2745
  def _find_library_internal(
2697
2746
  name: str,
2698
2747
  working_dir: str = ".",
@@ -2717,7 +2766,7 @@ def _find_library_internal(
2717
2766
  result = name
2718
2767
 
2719
2768
  if is_library_by_path(result):
2720
- result = robot_find_file(result, base_dir or ".", "Library")
2769
+ result = _find_import_file(result, base_dir, "Library")
2721
2770
 
2722
2771
  return (result, robot_variables)
2723
2772
 
@@ -2853,20 +2902,25 @@ def get_library_doc(
2853
2902
  ),
2854
2903
  module_spec=module_spec,
2855
2904
  errors=[
2856
- error_from_exception(
2857
- e,
2858
- (
2859
- source or module_spec.origin
2860
- if module_spec is not None and module_spec.origin
2861
- else import_name
2862
- if is_library_by_path(import_name)
2863
- else None
2864
- ),
2865
- (
2866
- 1
2867
- if source is not None or (module_spec is not None and module_spec.origin is not None)
2868
- else None
2905
+ _mark_not_found(
2906
+ error_from_exception(
2907
+ e,
2908
+ (
2909
+ source or module_spec.origin
2910
+ if module_spec is not None and module_spec.origin
2911
+ else import_name
2912
+ if is_library_by_path(import_name)
2913
+ else None
2914
+ ),
2915
+ (
2916
+ 1
2917
+ if source is not None or (module_spec is not None and module_spec.origin is not None)
2918
+ else None
2919
+ ),
2869
2920
  ),
2921
+ e,
2922
+ import_name,
2923
+ DiagnosticError.LIBRARY_NOT_FOUND,
2870
2924
  )
2871
2925
  ],
2872
2926
  python_path=sys.path,
@@ -2907,13 +2961,9 @@ def get_library_doc(
2907
2961
  raise
2908
2962
  except BaseException as e:
2909
2963
  lib = None
2910
- errors.append(
2911
- error_from_exception(
2912
- e,
2913
- source or module_spec.origin if module_spec is not None else None,
2914
- 1 if source is not None or (module_spec is not None and module_spec.origin is not None) else None,
2915
- )
2916
- )
2964
+ # no default source: only a traceback makes it an error inside the library's file, wrong
2965
+ # arguments or a `DataError` from `__init__` are errors of the import, by name and by path alike
2966
+ errors.append(error_from_exception(e, None, None))
2917
2967
 
2918
2968
  if args:
2919
2969
  try:
@@ -3281,7 +3331,7 @@ def _find_variables_internal(
3281
3331
  result = name
3282
3332
 
3283
3333
  if is_variables_by_path(result):
3284
- result = robot_find_file(result, base_dir or ".", "Variables")
3334
+ result = _find_import_file(result, base_dir, "Variables")
3285
3335
 
3286
3336
  return result
3287
3337
 
@@ -3550,16 +3600,23 @@ def get_variables_doc(
3550
3600
  source=source or module_spec.origin if module_spec is not None else import_name,
3551
3601
  module_spec=module_spec,
3552
3602
  errors=[
3553
- error_from_exception(
3554
- e,
3555
- (
3556
- source or module_spec.origin
3557
- if module_spec is not None and module_spec.origin
3558
- else import_name
3559
- if is_variables_by_path(import_name)
3560
- else None
3603
+ _mark_not_found(
3604
+ error_from_exception(
3605
+ e,
3606
+ (
3607
+ source or module_spec.origin
3608
+ if module_spec is not None and module_spec.origin
3609
+ else import_name
3610
+ if is_variables_by_path(import_name)
3611
+ else None
3612
+ ),
3613
+ 1
3614
+ if source is not None or (module_spec is not None and module_spec.origin is not None)
3615
+ else None,
3561
3616
  ),
3562
- 1 if source is not None or (module_spec is not None and module_spec.origin is not None) else None,
3617
+ e,
3618
+ import_name,
3619
+ DiagnosticError.VARIABLES_NOT_FOUND,
3563
3620
  )
3564
3621
  ],
3565
3622
  python_path=sys.path,
@@ -3583,7 +3640,7 @@ def find_file(
3583
3640
  except DataError as error:
3584
3641
  raise DataError(f"Replacing variables from setting '{file_type}' failed: {error}")
3585
3642
 
3586
- return cast(str, robot_find_file(name, base_dir or ".", file_type))
3643
+ return _find_import_file(name, base_dir, file_type)
3587
3644
 
3588
3645
 
3589
3646
  class CompleteResultKind(Enum):
@@ -4176,7 +4233,7 @@ def get_model_doc(
4176
4233
  else:
4177
4234
  lib = res
4178
4235
 
4179
- return _build_resource_doc(
4236
+ doc = _build_resource_doc(
4180
4237
  lib,
4181
4238
  source,
4182
4239
  keyword_name_nodes=res_builder.keyword_name_nodes,
@@ -4184,6 +4241,30 @@ def get_model_doc(
4184
4241
  resource_imports=res_builder.imports,
4185
4242
  resource_variables=res_builder.variables,
4186
4243
  )
4244
+ doc.import_error = _resource_import_error(model, source)
4245
+ return doc
4246
+
4247
+
4248
+ # Robot Framework's builder refuses a resource file at an invalid section header from 6.1 on, and at a fatal
4249
+ # error token (a test or task section) before
4250
+ _RESOURCE_FATAL_TOKEN = RobotToken.INVALID_HEADER if RF_VERSION >= (6, 1) else RobotToken.FATAL_ERROR
4251
+
4252
+
4253
+ def _resource_import_error(model: ast.AST, source: str) -> Optional[Error]:
4254
+ # the lexer puts these tokens into a section header or a statement directly in a section
4255
+ for section in getattr(model, "sections", ()):
4256
+ for statement in (section.header, *section.body):
4257
+ if not isinstance(statement, Statement):
4258
+ continue
4259
+ token = statement.get_token(_RESOURCE_FATAL_TOKEN)
4260
+ if token is not None:
4261
+ return Error(
4262
+ message=f"Error in file '{source}' on line {token.lineno}: {token.error}",
4263
+ type_name="DataError",
4264
+ source=source,
4265
+ line_no=token.lineno,
4266
+ )
4267
+ return None
4187
4268
 
4188
4269
 
4189
4270
  def get_resource_doc_from_resource(resource: Any, source: Optional[str] = None) -> ResourceDoc:
@@ -460,7 +460,10 @@ class Namespace:
460
460
 
461
461
  def _on_resources_changed(self, sender: Any, resources: Any) -> None:
462
462
  for p in resources:
463
- if any(e for e in self.resources.values() if e.library_doc.source == p.source):
463
+ if any(e for e in self.resources.values() if e.library_doc.source == p.source) or (
464
+ # a resource file Robot Framework refused is not imported, but fixing it changes the result
465
+ p.source is not None and any(f.source == str(normalized_path(p.source)) for f in self._failed_imports)
466
+ ):
464
467
  self.invalidated(self)
465
468
  return
466
469
 
@@ -799,7 +802,9 @@ class NamespaceBuilder:
799
802
  if self._disk_info is not None
800
803
  else None
801
804
  )
802
- library_doc = self._imports_manager.get_libdoc_from_model(self._model, self._source, source_meta)
805
+ library_doc = self._imports_manager.get_libdoc_from_model(
806
+ self._model, self._source, source_meta, suite_model=self._document_type != DocumentType.RESOURCE
807
+ )
803
808
  document_uri = (
804
809
  self._document.document_uri if self._document is not None else str(Uri.from_path(self._source))
805
810
  )
@@ -4,8 +4,15 @@ import sys
4
4
  from os import PathLike
5
5
  from typing import List, Optional, Union
6
6
 
7
+ from robot.errors import DataError
8
+
7
9
  _PathLike = Union[str, "PathLike[str]"]
8
10
 
11
+
12
+ class ImportNotFoundError(DataError):
13
+ """The file of a `Library`, `Resource` or `Variables` import does not exist."""
14
+
15
+
9
16
  # Cache of sys.path entries that are valid directories.
10
17
  # Populated lazily on first use; call invalidate_sys_path_cache()
11
18
  # if sys.path changes during the process lifetime.
@@ -29,8 +36,6 @@ def find_file_ex(
29
36
  basedir: _PathLike = ".",
30
37
  file_type: Optional[str] = None,
31
38
  ) -> str:
32
- from robot.errors import DataError
33
-
34
39
  ret = _find_absolute_path(path) if os.path.isabs(path) else _find_relative_path(path, basedir)
35
40
  if ret:
36
41
  return ret
@@ -47,7 +52,7 @@ def find_file_ex(
47
52
  else default
48
53
  )
49
54
 
50
- raise DataError("%s '%s' does not exist." % (file_type, path))
55
+ raise ImportNotFoundError("%s '%s' does not exist." % (file_type, path))
51
56
 
52
57
 
53
58
  def find_file(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: robotcode-robot
3
- Version: 2.9.0-dev.230
3
+ Version: 2.9.0-dev.264
4
4
  Summary: Support classes for RobotCode for handling Robot Framework projects.
5
5
  Project-URL: Homepage, https://robotcode.io
6
6
  Project-URL: Donate, https://opencollective.com/robotcode
@@ -27,7 +27,7 @@ Classifier: Topic :: Utilities
27
27
  Classifier: Typing :: Typed
28
28
  Requires-Python: >=3.10
29
29
  Requires-Dist: platformdirs>=4.3
30
- Requires-Dist: robotcode-core==2.9.0-dev.230
30
+ Requires-Dist: robotcode-core==2.9.0-dev.264
31
31
  Requires-Dist: robotframework>=5.0.0
32
32
  Requires-Dist: tomli>=1.1.0; python_version < '3.11'
33
33
  Description-Content-Type: text/markdown
@@ -1,26 +1,26 @@
1
1
  robotcode/robot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- robotcode/robot/__version__.py,sha256=ywQBe3tPie4G6fmOEZtLhXB6uR6pzyY-tUvQqJnZ3Rs,30
2
+ robotcode/robot/__version__.py,sha256=VN16WdRl9zxi7GbqkKoJDxt27F6zUDxjqn8r4zFJsGs,30
3
3
  robotcode/robot/document_formats.py,sha256=65dsIzcPkpnNd-WyhkSVSQbHdx6rI7kMq--8AvdDmuM,4842
4
4
  robotcode/robot/language_definitions.py,sha256=actqkDp12a11whu2TfKZU3xGk7Hk29HYLDTfeKZ1kqE,1449
5
5
  robotcode/robot/py.typed,sha256=bWew9mHgMy8LqMu7RuqQXFXLBxh2CRx0dUbSx-3wE48,27
6
6
  robotcode/robot/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  robotcode/robot/config/loader.py,sha256=HLbkZem8JiBuy9Q5naghZddAuMPOn8Tk6UBgN2T3Uyc,9073
8
- robotcode/robot/config/model.py,sha256=2dRKRDQV50_k1PmX-7uhqrPTX7Z6oJq4PcAG4pBDRi8,115165
8
+ robotcode/robot/config/model.py,sha256=waVbVvy_js5A22mucP87oPJHfJpu_tCCQHJ5x9RMcuA,115389
9
9
  robotcode/robot/config/utils.py,sha256=A8gD5IItxuC7AY5Olcc8tmsSbqCCi_vZPVoK3BqWt_8,4070
10
10
  robotcode/robot/diagnostics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  robotcode/robot/diagnostics/analyzer_result.py,sha256=5pHW5Yf3C3rmaDvmM7tP0y_qwqLW3YHhkeVV-qDhxtg,1459
12
12
  robotcode/robot/diagnostics/data_cache.py,sha256=Yi52oQTUBFgcPK0UF3lDAj4mRFqoD_VOtrAUyRWXnrQ,18200
13
13
  robotcode/robot/diagnostics/diagnostic_rules.py,sha256=DAeCg65dhCxoKUKSkKqo7zcgZ-fr9RXyj5yB3KYVq2A,3855
14
14
  robotcode/robot/diagnostics/diagnostics_modifier.py,sha256=MftxJlUEDsn9ZiOsBDApXC2N-4OjXHSZj1Y9PXXlSAg,11742
15
- robotcode/robot/diagnostics/document_cache_helper.py,sha256=GBpXlVqPTtLz6IpnZN6IJdkhIZorVDmse3yRuBQwLRY,37185
15
+ robotcode/robot/diagnostics/document_cache_helper.py,sha256=LOSBeZ0ywx3UFEbJhAARVgAzGLt-F5KU6RDCHxNFm2w,37273
16
16
  robotcode/robot/diagnostics/entities.py,sha256=vE5szceIL-ANqJPnAbqIebg3kLddE9OPhxwBL9iKP-M,11949
17
- robotcode/robot/diagnostics/errors.py,sha256=lqHDWrMNy3ZhuEIVxeEhaU0ns8PB6pVTQBfaMqRQ8L4,2733
18
- robotcode/robot/diagnostics/import_resolver.py,sha256=DZjUOD3uNxFAwsVUqrCTRhColjz9DRPetAvIb_Ccufs,32588
19
- robotcode/robot/diagnostics/imports_manager.py,sha256=F5tX-wVojpTitkN-IMhuLH0m1KF_95Lb5-eY6f37m7E,90458
17
+ robotcode/robot/diagnostics/errors.py,sha256=eh4-a09caKpddRFYXDqDS9wkKE6hza2sxXvUbtlkaFA,3021
18
+ robotcode/robot/diagnostics/import_resolver.py,sha256=zOzFLxP-9KzelKPVdQE6ajse5P4lzxlcMLAUEhmlwNU,34307
19
+ robotcode/robot/diagnostics/imports_manager.py,sha256=kJ2vCcTUCYejF7xkNPJ_qvq40UaOEplRy2Mh8uR6Q40,92184
20
20
  robotcode/robot/diagnostics/keyword_finder.py,sha256=nwTmjvhyu5H7HHzyk8gt-pny2K2xdH2qCNyKXwwXRnk,18998
21
- robotcode/robot/diagnostics/library_doc.py,sha256=w-_JhQ2gsHjIFEHh9-02HVmSP-SKzGuT8AHw5DuE38c,155575
21
+ robotcode/robot/diagnostics/library_doc.py,sha256=d6IPnK8O6_c-wOsj3LDsGB4jeF-0Q094-fmTQf4Hwus,159345
22
22
  robotcode/robot/diagnostics/model_helper.py,sha256=_ySXwerkK5xvjWa82T0DFy8jpxRzcaavTJiAHnk2lXQ,29740
23
- robotcode/robot/diagnostics/namespace.py,sha256=Rcmjk3V0vcY-DUkgjkRyuOdYXurKaTEqXJLc6efYrwY,35489
23
+ robotcode/robot/diagnostics/namespace.py,sha256=sBOA6I3W5QJf67AbRD7XefRL2O7ncQQqLkWVAuTnLbY,35823
24
24
  robotcode/robot/diagnostics/namespace_analyzer.py,sha256=oGO-Tz811whfiOTNoKudH8wPr0bbOwwefiquN0_XYh0,104253
25
25
  robotcode/robot/diagnostics/project_index.py,sha256=Oqs7kV279PixVS6rGeigPKXGJYGqJdTDmDBjU7ODDRA,11006
26
26
  robotcode/robot/diagnostics/scope_tree.py,sha256=UREHoFG7NWh6UTWxET1M5Jxz_XBjXaQJg1GUIYPctq0,8348
@@ -42,10 +42,10 @@ robotcode/robot/utils/markdown_docs.py,sha256=jR1gfOAyf0C6i-Gn9Q2cStHogAUXcM-jFN
42
42
  robotcode/robot/utils/markdownformatter.py,sha256=HjFLZK1whOghijdKAyw3NciCI_JrCmlUtst1rl8VTMA,17390
43
43
  robotcode/robot/utils/match.py,sha256=KgA6o6TbnQpOT1eAzEjhl_-FZ2XO07xiV0L7IYRzyzE,1125
44
44
  robotcode/robot/utils/robot_patching.py,sha256=jXHhnPvZx8hCQq4B_2uwX9j51Be_toWpUoTYYe8HjPo,1463
45
- robotcode/robot/utils/robot_path.py,sha256=ObLP8PqamTZAz5oi0eDXE_dnyZwAPXp4TJYm6ugeENs,2185
45
+ robotcode/robot/utils/robot_path.py,sha256=9WtnzI7ozK0stppr3HxMhqDkJGI0ZuwEa-9J-ONBmjg,2316
46
46
  robotcode/robot/utils/stubs.py,sha256=umugZYAyneFNgqRJBRMJPzm0u0B_TH8Sx_y-ykXnxpw,351
47
47
  robotcode/robot/utils/variables.py,sha256=9WnP3QqcHdq-zioJ_gJXJobw_2Gcto_rGPCUGmOH9YQ,9829
48
48
  robotcode/robot/utils/visitor.py,sha256=nP3O0qh3YYuxR6S8wYJRBFfNwIVgsgohURBlrnFkRYQ,2299
49
- robotcode_robot-2.9.0.dev230.dist-info/METADATA,sha256=6SnTOV-IEhzdkXpCwk-QyVmsYJNdGhkw471Po77dmCY,2960
50
- robotcode_robot-2.9.0.dev230.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
51
- robotcode_robot-2.9.0.dev230.dist-info/RECORD,,
49
+ robotcode_robot-2.9.0.dev264.dist-info/METADATA,sha256=h8G_c0mkTP3aSWdFl5S3rQJ7MbYWw-zZp3MeONqikV0,2960
50
+ robotcode_robot-2.9.0.dev264.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
51
+ robotcode_robot-2.9.0.dev264.dist-info/RECORD,,