diff options
author | Frederick Muriuki Muriithi | 2024-12-09 11:34:14 -0600 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-12-09 11:39:34 -0600 |
commit | d8eb7c2d983f4b7382db47c384bc673baccd170c (patch) | |
tree | e42cc794d7db9af25c67e0110346940fb1693229 | |
parent | 5f5e33daaf909a5dbc5b0a1730c7510f19576548 (diff) | |
download | gn-libs-d8eb7c2d983f4b7382db47c384bc673baccd170c.tar.gz |
Fix check for non-negative integers.
-rw-r--r-- | gn_libs/mysqldb.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/gn_libs/mysqldb.py b/gn_libs/mysqldb.py index 4997ac7..445b073 100644 --- a/gn_libs/mysqldb.py +++ b/gn_libs/mysqldb.py @@ -26,9 +26,14 @@ def __parse_boolean__(val: str) -> bool: def __non_negative_int__(val: str) -> int: """Convert a value to a non-negative int.""" - _val = int(val) - assert (val >= 0), f"Expected a non-negative value. Got {_val}" - return _val + error_message = f"Expected a non-negative value. Got {val}" + try: + _val = int(val) + if (_val < 0): + raise InvalidOptionValue(error_message) + return _val + except ValueError as verr: + raise InvalidOptionValue(error_message) from verr def __parse_ssl_mode_options__(val: str) -> str: |