From d8eb7c2d983f4b7382db47c384bc673baccd170c Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 9 Dec 2024 11:34:14 -0600 Subject: Fix check for non-negative integers. --- gn_libs/mysqldb.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'gn_libs/mysqldb.py') 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: -- cgit v1.2.3