From f320ea1e2b031afe4d2e013345989977475ee039 Mon Sep 17 00:00:00 2001 From: Charles Lanahan Date: Sat, 29 Jun 2024 13:51:27 +0900 Subject: [PATCH 1/2] Fixed KERI_BASER_MAP_SIZE not integer bug. Added log message and exception check for when KERI_BASER_MAP_SIZE not an integer. Signed-off-by: Charles Lanahan --- src/keri/db/basing.py | 5 ++++- tests/db/test_basing.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/keri/db/basing.py b/src/keri/db/basing.py index 8294cf551..15473b12d 100644 --- a/src/keri/db/basing.py +++ b/src/keri/db/basing.py @@ -939,7 +939,10 @@ def __init__(self, headDirPath=None, reopen=False, **kwa): self._kevers.db = self # assign db for read through cache of kevers if (mapSize := os.getenv(KERIBaserMapSizeKey)) is not None: - self.MapSize = int(mapSize) + try: + self.MapSize = int(mapSize) + except ValueError: + logger.exception("KERI_BASER_MAP_SIZE must be an integer value! Will continue to use default keripy value of 104857600!") super(Baser, self).__init__(headDirPath=headDirPath, reopen=reopen, **kwa) diff --git a/tests/db/test_basing.py b/tests/db/test_basing.py index 43d575007..ca4a23dde 100644 --- a/tests/db/test_basing.py +++ b/tests/db/test_basing.py @@ -2338,6 +2338,16 @@ def test_group_members(): """End Test""" +def test_KERI_BASER_MAP_SIZE_handles_bad_values(): + # Base case works because of above tests, they will all break if happy path + # is broken. We'll just test some unhappy values. + + # Pytest will fail if any exceptions raised here. + os.putenv("KERI_BASER_MAP_SIZE", "foo") # Not an int + baser = Baser(reopen=False) + os.putenv("KERI_BASER_MAP_SIZE", "1.0") # Not an int + baser = Baser(reopen=False) + if __name__ == "__main__": test_baser() From c6153fc11d8cbbf947459e0356814e0894198081 Mon Sep 17 00:00:00 2001 From: Charles Lanahan Date: Sat, 6 Jul 2024 14:54:06 +0900 Subject: [PATCH 2/2] Rethrow exception per PR request to fail fast. Updated log message to reflect the issue --- src/keri/db/basing.py | 3 ++- tests/db/test_basing.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/keri/db/basing.py b/src/keri/db/basing.py index 15473b12d..7426ae733 100644 --- a/src/keri/db/basing.py +++ b/src/keri/db/basing.py @@ -942,7 +942,8 @@ def __init__(self, headDirPath=None, reopen=False, **kwa): try: self.MapSize = int(mapSize) except ValueError: - logger.exception("KERI_BASER_MAP_SIZE must be an integer value! Will continue to use default keripy value of 104857600!") + logger.error("KERI_BASER_MAP_SIZE must be an integer value >1!") + raise super(Baser, self).__init__(headDirPath=headDirPath, reopen=reopen, **kwa) diff --git a/tests/db/test_basing.py b/tests/db/test_basing.py index ca4a23dde..89044c7d9 100644 --- a/tests/db/test_basing.py +++ b/tests/db/test_basing.py @@ -2338,15 +2338,21 @@ def test_group_members(): """End Test""" -def test_KERI_BASER_MAP_SIZE_handles_bad_values(): +def test_KERI_BASER_MAP_SIZE_handles_bad_values(caplog): # Base case works because of above tests, they will all break if happy path # is broken. We'll just test some unhappy values. # Pytest will fail if any exceptions raised here. - os.putenv("KERI_BASER_MAP_SIZE", "foo") # Not an int - baser = Baser(reopen=False) - os.putenv("KERI_BASER_MAP_SIZE", "1.0") # Not an int - baser = Baser(reopen=False) + os.environ["KERI_BASER_MAP_SIZE"] = "foo" # Not an int + err_msg = "KERI_BASER_MAP_SIZE must be an integer value > 1!" + with pytest.raises(ValueError): + Baser(reopen=False, temp=True) + assert err_msg in caplog.messages + os.environ["KERI_BASER_MAP_SIZE"] = "1.0" # Not an int + with pytest.raises(ValueError): + Baser(reopen=False, temp=True) + assert err_msg in caplog.messages + os.environ.pop("KERI_BASER_MAP_SIZE") if __name__ == "__main__":