Skip to content

Commit

Permalink
Fixed KERI_BASER_MAP_SIZE not integer bug. (#812)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Rethrow exception per PR request to fail fast.  Updated log message to reflect the issue

---------

Signed-off-by: Charles Lanahan <[email protected]>
  • Loading branch information
daidoji authored Jul 8, 2024
1 parent 6b6970b commit 59a0c8a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/keri/db/basing.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,11 @@ 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.error("KERI_BASER_MAP_SIZE must be an integer value >1!")
raise

super(Baser, self).__init__(headDirPath=headDirPath, reopen=reopen, **kwa)

Expand Down
16 changes: 16 additions & 0 deletions tests/db/test_basing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,22 @@ def test_group_members():

"""End Test"""

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.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__":
test_baser()
Expand Down

0 comments on commit 59a0c8a

Please sign in to comment.