1
Fork 0
mirror of https://github.com/Steffo99/cfig.git synced 2024-10-16 14:27:38 +00:00

🧪 Catch TypeError in the config

This commit is contained in:
Steffo 2022-04-26 18:00:44 +02:00
parent f773c7577e
commit 809cf435fb
Signed by: steffo
GPG key ID: 6965406171929D01
2 changed files with 4 additions and 4 deletions

View file

@ -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

View file

@ -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__":