From 7c478473ddd3278dbbbd1520c6a290a270663e53 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 16 Aug 2020 22:07:34 -0500 Subject: Document ParsingError and ConfigFile init errors --- README.md | 15 +++++++++++++++ config_file/config_file.py | 1 + config_file/config_file_path.py | 1 + 3 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 8beb1d2..52f731a 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,21 @@ from config_file import ConfigFile config = ConfigFile("~/some-project/config.ini") ``` +#### Handling ConfigFile Initialization Errors + +```python +from config_file import ConfigFile, ParsingError + +try: + config = ConfigFile("~/some-file.ini") +except ParsingError: + print("could not parse the file") +except ValueError: + print("extension that isn't supported was used or is a directory") +except FileNotFoundError: + print("file does not exist") +``` + ### Using `get()` A recurring pattern you'll see here is that all methods that diff --git a/config_file/config_file.py b/config_file/config_file.py index 2a8d9ae..934c198 100644 --- a/config_file/config_file.py +++ b/config_file/config_file.py @@ -21,6 +21,7 @@ class ConfigFile: ValueError: If the specified file path does not have an extension that is supported or it is a directory. FileNotFoundError: If the specified file path does not exist. + ParsingError: If the file_path could not be parsed. """ self.__path = ConfigFilePath(file_path).validate() self.__parser = self.__path.parser diff --git a/config_file/config_file_path.py b/config_file/config_file_path.py index 11a5daa..ecb6531 100644 --- a/config_file/config_file_path.py +++ b/config_file/config_file_path.py @@ -58,6 +58,7 @@ class ConfigFilePath(_Path_): Raises: ValueError: If the extension of the file is not recognized. + ParsingError: If the contents could not be parsed. Returns: The instantiated parser that should be used for this file. -- cgit v1.2.3