From 65011a67d451d1ad285613a4becf4bb624dfb2a6 Mon Sep 17 00:00:00 2001 From: cachho Date: Wed, 9 Aug 2023 05:36:26 +0200 Subject: [PATCH] fix: is readable - zero division error (#383) --- embedchain/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/embedchain/utils.py b/embedchain/utils.py index d0a7c1e1..6ca2b9df 100644 --- a/embedchain/utils.py +++ b/embedchain/utils.py @@ -1,3 +1,4 @@ +import logging import re import string @@ -43,7 +44,11 @@ def is_readable(s): :param s: string :return: True if the string is more than 95% printable. """ - printable_ratio = sum(c in string.printable for c in s) / len(s) + try: + printable_ratio = sum(c in string.printable for c in s) / len(s) + except ZeroDivisionError: + logging.warning("Empty string processed as unreadable") + printable_ratio = 0 return printable_ratio > 0.95 # 95% of characters are printable