Skip to content

Commit

Permalink
feat(bot): 🥅 catch any other error when loading FastAPIManager
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Jul 26, 2024
1 parent 299c07f commit 2314f31
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/bot/bot/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
from bot.event_handler import EventHandler
from bot.location import Location

# FastAPIManager
fastapi_error = None
try:
from bot.fastapi_manager import FastAPIManager
except ImportError:
FastAPIManager = None
except Exception as e:
FastAPIManager = None
fastapi_error = e


class Plugin:
Expand All @@ -35,10 +40,19 @@ def load_fastapi_manager(self):
if FastAPIManager is not None:
self.__fastapi_manager = FastAPIManager(self)
else:
self.server.logger.debug(
"FastAPI library is not installed, "
"will not register APIs with FastAPI MCDR."
)
if fastapi_error is None:
self.server.logger.debug(
"FastAPI libraries is not installed, "
"will not register APIs with FastAPI MCDR."
)
else:
self.server.logger.warning(
"Failed to load FastAPI manager, "
"please check the error message below. "
"If you do not intent to use FastAPI, "
"you may ignore this message.",
exc_info=fastapi_error
)

def unload_fastapi_manager(self):
if self.__fastapi_manager is not None:
Expand Down

0 comments on commit 2314f31

Please sign in to comment.