Skip to content

Commit

Permalink
Added OSError handling
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>
  • Loading branch information
ElenaKhaustova committed Jun 3, 2024
1 parent ea5da0d commit f293349
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions kedro-telemetry/kedro_telemetry/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _get_or_create_project_id(pyproject_path: Path) -> str | None:
Reads a project id from a configuration file or generates and saves a new one if not present.
Returns None if configuration file does not exist or does not relate to Kedro.
"""
if pyproject_path.exists():
try:
with open(pyproject_path, "r+") as file:
pyproject_data = toml.load(file)

Expand All @@ -102,15 +102,13 @@ def _get_or_create_project_id(pyproject_path: Path) -> str | None:
file.write(toml_string)
return project_id
except KeyError:
logging.debug(
logging.error(
f"Failed to retrieve project id or save project id: "
f"{str(pyproject_path)} does not contain a [tool.kedro] section"
)
return None

logging.debug(
f"Failed to retrieve project id or save project id: {str(pyproject_path)} does not exist"
)
except OSError as exc:
logging.error(f"Failed to read the file: {str(pyproject_path)}.\n{str(exc)}")
return None


Expand Down

0 comments on commit f293349

Please sign in to comment.