Skip to content

Commit

Permalink
add log (#2266)
Browse files Browse the repository at this point in the history
Signed-off-by: ravi_kumar_pilla <ravi_kumar_pilla@mckinsey.com>
  • Loading branch information
ravi-kumar-pilla authored Feb 3, 2025
1 parent 4b58ad2 commit 65f2c5a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
17 changes: 13 additions & 4 deletions package/kedro_viz/integrations/kedro/lite_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,17 @@ def parse(self, target_path: Path) -> Union[Dict[str, Set[str]], None]:
unresolved_imports: Dict[str, Set[str]] = {}

if target_path.is_file():
missing_dependencies = self._get_unresolved_imports(target_path)
if len(missing_dependencies) > 0:
unresolved_imports[str(target_path)] = missing_dependencies
try:
missing_dependencies = self._get_unresolved_imports(target_path)
if len(missing_dependencies) > 0:
unresolved_imports[str(target_path)] = missing_dependencies
except Exception as exc: # noqa: BLE001
logger.error(
"An error occurred in LiteParser while mocking dependencies in %s : %s",
target_path,
exc,
)

return unresolved_imports

# handling directories
Expand All @@ -263,7 +271,8 @@ def parse(self, target_path: Path) -> Union[Dict[str, Set[str]], None]:
unresolved_imports[str(file_path)] = missing_dependencies
except Exception as exc: # noqa: BLE001 # pragma: no cover
logger.error(
"An error occurred in LiteParser while mocking dependencies : %s",
"An error occurred in LiteParser while mocking dependencies in %s : %s",
file_path,
exc,
)
continue
Expand Down
19 changes: 19 additions & 0 deletions package/tests/test_integrations/test_lite_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ def test_file_parse(self, lite_parser, sample_project_path):

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

def test_parse_logs_error_on_exception(self, lite_parser, tmp_path, caplog):
file_path = Path(tmp_path / "mock_spaceflights/data_processing_non_utf.py")
file_path.parent.mkdir(parents=True, exist_ok=True)

# Write non-UTF characters (e.g., using ISO-8859-1 encoding)
non_utf_content = "This is a test with non-UTF characters: é, ñ, ü"

# Write the file in ISO-8859-1 encoding
with open(file_path, "w", encoding="ISO-8859-1") as f:
f.write(non_utf_content)

assert file_path.exists()

lite_parser.parse(file_path)
assert (
f"An error occurred in LiteParser while mocking dependencies in {str(file_path)}"
in caplog.text
)

def test_directory_parse(self, lite_parser, sample_project_path):
unresolved_imports = lite_parser.parse(sample_project_path)
expected_file_path = Path(
Expand Down

0 comments on commit 65f2c5a

Please sign in to comment.