diff options
Diffstat (limited to '')
| -rw-r--r-- | taskipy/exceptions.py | 12 | ||||
| -rw-r--r-- | taskipy/pyproject.py | 9 |
2 files changed, 16 insertions, 5 deletions
diff --git a/taskipy/exceptions.py b/taskipy/exceptions.py index 573967e..d54a022 100644 --- a/taskipy/exceptions.py +++ b/taskipy/exceptions.py @@ -1,4 +1,5 @@ from argparse import ArgumentParser +from typing import Optional class TaskipyError(Exception): exit_code = 1 @@ -18,8 +19,17 @@ class MissingPyProjectFileError(TaskipyError): class MalformedPyProjectError(TaskipyError): + def __init__(self, reason: Optional[str] = None): + super().__init__() + self.reason = reason + def __str__(self): - return 'pyproject.toml file is malformed and could not be read' + message = 'pyproject.toml file is malformed and could not be read' + + if self.reason: + message += f'. reason: {self.reason}' + + return message class TaskNotFoundError(TaskipyError): diff --git a/taskipy/pyproject.py b/taskipy/pyproject.py index 702aad0..d59d6ac 100644 --- a/taskipy/pyproject.py +++ b/taskipy/pyproject.py @@ -1,4 +1,4 @@ -import toml +import tomli from pathlib import Path from typing import Any, Dict, MutableMapping, Optional, Union @@ -58,11 +58,12 @@ class PyProject: if isinstance(file_path, str): file_path = Path(file_path).resolve() - return toml.load(file_path) + with open(file_path, 'rb') as file: + return tomli.load(file) except FileNotFoundError: raise MissingPyProjectFileError() - except toml.TomlDecodeError: - raise MalformedPyProjectError() + except tomli.TOMLDecodeError as e: + raise MalformedPyProjectError(reason=str(e)) @staticmethod def __find_pyproject_path(base_dir: Path) -> Path: |