🐛 fix(loading.py): catch additional exception when object has no 'conn' field to improve error handling

The code now catches an additional exception when the object does not have a 'conn' field. This improves the error handling by providing a more specific error message when building a connection to the database fails.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-29 18:38:36 -03:00
commit 08c7bb5230

View file

@ -93,8 +93,10 @@ def instantiate_memory(node_type, class_object, params):
return class_object(**params)
# I want to catch a specific attribute error that happens
# when the object does not have a cursor attribute
except AttributeError as exc:
if "object has no attribute 'cursor'" in str(exc):
except Exception as exc:
if "object has no attribute 'cursor'" in str(
exc
) or 'object has no field "conn"' in str(exc):
raise AttributeError(
f"Failed to build connection to database. Please check your connection string and try again. Error: {exc}"
) from exc