mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
possible mongo fix (#3319)
* possible mongo fix * prevent swallowing the exception * better log str
This commit is contained in:
parent
ed692bcaa5
commit
acc5baec7d
@ -466,6 +466,10 @@ def main():
|
|||||||
log.info("Shutting down with exit code: %s", exc.code)
|
log.info("Shutting down with exit code: %s", exc.code)
|
||||||
if red is not None:
|
if red is not None:
|
||||||
loop.run_until_complete(shutdown_handler(red, None, exc.code))
|
loop.run_until_complete(shutdown_handler(red, None, exc.code))
|
||||||
|
except Exception as exc: # Non standard case.
|
||||||
|
log.exception("Unexpected exception (%s): ", type(exc), exc_info=exc)
|
||||||
|
if red is not None:
|
||||||
|
loop.run_until_complete(shutdown_handler(red, None, ExitCodes.CRITICAL))
|
||||||
finally:
|
finally:
|
||||||
# Allows transports to close properly, and prevent new ones from being opened.
|
# Allows transports to close properly, and prevent new ones from being opened.
|
||||||
# Transports may still not be closed correcly on windows, see below
|
# Transports may still not be closed correcly on windows, see below
|
||||||
|
|||||||
@ -643,7 +643,14 @@ class Config:
|
|||||||
return pickle.loads(pickle.dumps(self._defaults, -1))
|
return pickle.loads(pickle.dumps(self._defaults, -1))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_conf(cls, cog_instance, identifier: int, force_registration=False, cog_name=None):
|
def get_conf(
|
||||||
|
cls,
|
||||||
|
cog_instance,
|
||||||
|
identifier: int,
|
||||||
|
force_registration=False,
|
||||||
|
cog_name=None,
|
||||||
|
allow_old: bool = False,
|
||||||
|
):
|
||||||
"""Get a Config instance for your cog.
|
"""Get a Config instance for your cog.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
@ -676,11 +683,16 @@ class Config:
|
|||||||
A new Config object.
|
A new Config object.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if allow_old:
|
||||||
|
log.warning(
|
||||||
|
"DANGER! This is getting an outdated driver. "
|
||||||
|
"Hopefully this is only being done from convert"
|
||||||
|
)
|
||||||
uuid = str(identifier)
|
uuid = str(identifier)
|
||||||
if cog_name is None:
|
if cog_name is None:
|
||||||
cog_name = type(cog_instance).__name__
|
cog_name = type(cog_instance).__name__
|
||||||
|
|
||||||
driver = get_driver(cog_name, uuid)
|
driver = get_driver(cog_name, uuid, allow_old=allow_old)
|
||||||
if hasattr(driver, "migrate_identifier"):
|
if hasattr(driver, "migrate_identifier"):
|
||||||
driver.migrate_identifier(identifier)
|
driver.migrate_identifier(identifier)
|
||||||
|
|
||||||
@ -693,7 +705,7 @@ class Config:
|
|||||||
return conf
|
return conf
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_core_conf(cls, force_registration: bool = False):
|
def get_core_conf(cls, force_registration: bool = False, allow_old: bool = False):
|
||||||
"""Get a Config instance for the core bot.
|
"""Get a Config instance for the core bot.
|
||||||
|
|
||||||
All core modules that require a config instance should use this
|
All core modules that require a config instance should use this
|
||||||
@ -706,7 +718,11 @@ class Config:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
return cls.get_conf(
|
return cls.get_conf(
|
||||||
None, cog_name="Core", identifier=0, force_registration=force_registration
|
None,
|
||||||
|
cog_name="Core",
|
||||||
|
identifier=0,
|
||||||
|
force_registration=force_registration,
|
||||||
|
allow_old=allow_old,
|
||||||
)
|
)
|
||||||
|
|
||||||
def __getattr__(self, item: str) -> Union[Group, Value]:
|
def __getattr__(self, item: str) -> Union[Group, Value]:
|
||||||
@ -1457,7 +1473,7 @@ class Config:
|
|||||||
async def migrate(cur_driver_cls: Type[BaseDriver], new_driver_cls: Type[BaseDriver]) -> None:
|
async def migrate(cur_driver_cls: Type[BaseDriver], new_driver_cls: Type[BaseDriver]) -> None:
|
||||||
"""Migrate from one driver type to another."""
|
"""Migrate from one driver type to another."""
|
||||||
# Get custom group data
|
# Get custom group data
|
||||||
core_conf = Config.get_core_conf()
|
core_conf = Config.get_core_conf(allow_old=True)
|
||||||
core_conf.init_custom("CUSTOM_GROUPS", 2)
|
core_conf.init_custom("CUSTOM_GROUPS", 2)
|
||||||
all_custom_group_data = await core_conf.custom("CUSTOM_GROUPS").all()
|
all_custom_group_data = await core_conf.custom("CUSTOM_GROUPS").all()
|
||||||
|
|
||||||
|
|||||||
@ -73,7 +73,12 @@ def get_driver_class(storage_type: Optional[BackendType] = None) -> Type[BaseDri
|
|||||||
|
|
||||||
|
|
||||||
def get_driver(
|
def get_driver(
|
||||||
cog_name: str, identifier: str, storage_type: Optional[BackendType] = None, **kwargs
|
cog_name: str,
|
||||||
|
identifier: str,
|
||||||
|
storage_type: Optional[BackendType] = None,
|
||||||
|
*,
|
||||||
|
allow_old: bool = False,
|
||||||
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""Get a driver instance.
|
"""Get a driver instance.
|
||||||
|
|
||||||
@ -107,7 +112,10 @@ def get_driver(
|
|||||||
storage_type = BackendType.JSON
|
storage_type = BackendType.JSON
|
||||||
|
|
||||||
try:
|
try:
|
||||||
driver_cls: Type[BaseDriver] = get_driver_class(storage_type)
|
if not allow_old:
|
||||||
|
driver_cls: Type[BaseDriver] = get_driver_class(storage_type)
|
||||||
|
else:
|
||||||
|
driver_cls: Type[BaseDriver] = _get_driver_class_include_old(storage_type)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if storage_type in (BackendType.MONGOV1, BackendType.MONGO):
|
if storage_type in (BackendType.MONGOV1, BackendType.MONGO):
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user