diff options
| author | jvoisin | 2020-11-23 19:50:46 +0100 |
|---|---|---|
| committer | jvoisin | 2020-11-30 18:52:07 +0100 |
| commit | 61dce89fbd7759a9d2c19c46930030fd4467374f (patch) | |
| tree | 80ad1da86db63507f4b35acf205a5d2386247403 /libmat2 | |
| parent | 88b7ec2c48a63b158ee69b14dadc506f3359df5f (diff) | |
Raise a ValueError explicitly
Diffstat (limited to 'libmat2')
| -rw-r--r-- | libmat2/parser_factory.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/libmat2/parser_factory.py b/libmat2/parser_factory.py index 23529db..842f0d7 100644 --- a/libmat2/parser_factory.py +++ b/libmat2/parser_factory.py | |||
| @@ -40,7 +40,10 @@ def _get_parsers() -> List[T]: | |||
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | def get_parser(filename: str) -> Tuple[Optional[T], Optional[str]]: | 42 | def get_parser(filename: str) -> Tuple[Optional[T], Optional[str]]: |
| 43 | """ Return the appropriate parser for a given filename. """ | 43 | """ Return the appropriate parser for a given filename. |
| 44 | |||
| 45 | :raises ValueError: Raised if the instantiation of the parser went wrong. | ||
| 46 | """ | ||
| 44 | mtype, _ = mimetypes.guess_type(filename) | 47 | mtype, _ = mimetypes.guess_type(filename) |
| 45 | 48 | ||
| 46 | _, extension = os.path.splitext(filename) | 49 | _, extension = os.path.splitext(filename) |
| @@ -53,10 +56,6 @@ def get_parser(filename: str) -> Tuple[Optional[T], Optional[str]]: | |||
| 53 | 56 | ||
| 54 | for parser_class in _get_parsers(): # type: ignore | 57 | for parser_class in _get_parsers(): # type: ignore |
| 55 | if mtype in parser_class.mimetypes: | 58 | if mtype in parser_class.mimetypes: |
| 56 | try: | 59 | # This instantiation might raise a ValueError on malformed files |
| 57 | return parser_class(filename), mtype | 60 | return parser_class(filename), mtype |
| 58 | except ValueError as e: | ||
| 59 | logging.info("Got an exception when trying to instantiate " | ||
| 60 | "%s for %s: %s", parser_class, filename, e) | ||
| 61 | return None, mtype | ||
| 62 | return None, mtype | 61 | return None, mtype |
