mirror of
https://github.com/Steffo99/cfig.git
synced 2024-11-21 23:44:21 +00:00
🧪 Catch TypeError in the config
This commit is contained in:
parent
f773c7577e
commit
809cf435fb
2 changed files with 4 additions and 4 deletions
|
@ -58,7 +58,7 @@ class TestConfig:
|
|||
"""The first number to sum."""
|
||||
try:
|
||||
return int(val)
|
||||
except ValueError:
|
||||
except (ValueError, TypeError):
|
||||
raise cfig.InvalidValueError("Not an int.")
|
||||
|
||||
@basic_config.optional()
|
||||
|
@ -66,7 +66,7 @@ class TestConfig:
|
|||
"""The second number to sum."""
|
||||
try:
|
||||
return int(val)
|
||||
except ValueError:
|
||||
except (ValueError, TypeError):
|
||||
raise cfig.InvalidValueError("Not an int.")
|
||||
|
||||
yield basic_config
|
||||
|
|
|
@ -125,7 +125,7 @@ This allows us to perform some expensive operations inside, such as connecting t
|
|||
"""The maximum number of users that will be able to login to this application."""
|
||||
try:
|
||||
return int(val)
|
||||
except ValueError:
|
||||
except (ValueError, TypeError):
|
||||
raise cfig.InvalidValueError("Not an int.")
|
||||
|
||||
We can see that the new ``MAX_USERS`` configurable value processes the input string by trying to cast it into an :class:`int`, and raises a :exc:`~cfig.errors.InvalidValueError` containing the error message to display to the user if the cast fails.
|
||||
|
@ -168,7 +168,7 @@ To facilitate configuration on the users' part, :mod:`cfig` provides an integrat
|
|||
"""The maximum number of users that will be able to login to this application."""
|
||||
try:
|
||||
return int(val)
|
||||
except ValueError:
|
||||
except (ValueError, TypeError):
|
||||
raise cfig.InvalidValueError("Not an int.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue