From 2d2bc47ebcf2bb5c119526c43f7e4f134908e5a8 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Mon, 19 May 2025 12:40:15 +0100 Subject: [PATCH] Log errors upon failure to connect to ISPyB, but attempt to boot up Murfey as far as is possible --- src/murfey/server/ispyb.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/murfey/server/ispyb.py b/src/murfey/server/ispyb.py index c12bc3939..ddf55f87e 100644 --- a/src/murfey/server/ispyb.py +++ b/src/murfey/server/ispyb.py @@ -44,7 +44,8 @@ ) ) log.info("Loaded ISPyB database session") -except AttributeError: +# Catch all errors associated with loading ISPyB database +except Exception: log.error("Error loading ISPyB session", exc_info=True) ISPyBSession = lambda: None @@ -66,13 +67,17 @@ def __init__(self, transport_type: Literal["PikaTransport"]): self.transport = workflows.transport.lookup(transport_type)() self.transport.connect() self.feedback_queue = "" - self.ispyb = ( - ispyb.open(credentials=security_config.ispyb_credentials) - if security_config.ispyb_credentials - else None - ) - if self.ispyb is not None: - print("Loaded ISPyB databse") + try: + # Attempt to connect to ISPyB if credentials files provided + self.ispyb = ( + ispyb.open(credentials=security_config.ispyb_credentials) + if security_config.ispyb_credentials + else None + ) + except Exception: + # Log error and return None if the connection fails + log.error("Error encountered connecting to ISPyB server", exc_info=True) + self.ispyb = None self._connection_callback: Callable | None = None def reconnect(self):