Skip to content

Commit e0c61d7

Browse files
committed
Catch only KeyError when parsing enum
1 parent 37e1871 commit e0c61d7

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ README.html
5454
.mypy_cache
5555

5656
!tests/.env
57+
58+
#IDEs
59+
.idea/

environs/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ def _preprocess_json(value: str, **kwargs):
183183
def _enum_parser(value, *, type: typing.Type[_EnumT], **kwargs) -> _EnumT:
184184
try:
185185
return type[value]
186-
except Exception:
187-
raise ma.ValidationError(f"Not a valid {type} enum.")
186+
except KeyError:
187+
raise ma.ValidationError(f"Not a valid '{type.__name__}' enum.")
188188

189189

190190
def _dj_db_url_parser(value: str, **kwargs) -> dict:

0 commit comments

Comments
 (0)