Skip to content

Commit 6ea69ac

Browse files
add log
Signed-off-by: ravi_kumar_pilla <ravi_kumar_pilla@mckinsey.com>
1 parent 4b58ad2 commit 6ea69ac

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

package/kedro_viz/integrations/kedro/lite_parser.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,17 @@ def parse(self, target_path: Path) -> Union[Dict[str, Set[str]], None]:
240240
unresolved_imports: Dict[str, Set[str]] = {}
241241

242242
if target_path.is_file():
243-
missing_dependencies = self._get_unresolved_imports(target_path)
244-
if len(missing_dependencies) > 0:
245-
unresolved_imports[str(target_path)] = missing_dependencies
243+
try:
244+
missing_dependencies = self._get_unresolved_imports(target_path)
245+
if len(missing_dependencies) > 0:
246+
unresolved_imports[str(target_path)] = missing_dependencies
247+
except Exception as exc: # noqa: BLE001
248+
logger.error(
249+
"An error occurred in LiteParser while mocking dependencies in %s : %s",
250+
target_path,
251+
exc,
252+
)
253+
246254
return unresolved_imports
247255

248256
# handling directories
@@ -263,7 +271,8 @@ def parse(self, target_path: Path) -> Union[Dict[str, Set[str]], None]:
263271
unresolved_imports[str(file_path)] = missing_dependencies
264272
except Exception as exc: # noqa: BLE001 # pragma: no cover
265273
logger.error(
266-
"An error occurred in LiteParser while mocking dependencies : %s",
274+
"An error occurred in LiteParser while mocking dependencies in %s : %s",
275+
file_path,
267276
exc,
268277
)
269278
continue

package/tests/test_integrations/test_lite_parser.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,25 @@ def test_file_parse(self, lite_parser, sample_project_path):
179179

180180
assert unresolved_imports == {str(file_path): {"nonexistentmodule"}}
181181

182+
def test_parse_logs_error_on_exception(self, lite_parser, tmp_path, caplog):
183+
file_path = Path(tmp_path / "mock_spaceflights/data_processing_non_utf.py")
184+
file_path.parent.mkdir(parents=True, exist_ok=True)
185+
186+
# Write non-UTF characters (e.g., using ISO-8859-1 encoding)
187+
non_utf_content = "This is a test with non-UTF characters: é, ñ, ü"
188+
189+
# Write the file in ISO-8859-1 encoding
190+
with open(file_path, "w", encoding="ISO-8859-1") as f:
191+
f.write(non_utf_content)
192+
193+
assert file_path.exists()
194+
195+
lite_parser.parse(file_path)
196+
assert (
197+
f"An error occurred in LiteParser while mocking dependencies in {str(file_path)}"
198+
in caplog.text
199+
)
200+
182201
def test_directory_parse(self, lite_parser, sample_project_path):
183202
unresolved_imports = lite_parser.parse(sample_project_path)
184203
expected_file_path = Path(

0 commit comments

Comments
 (0)