#Raise exception when an extension failed to load and continue the rest

1 messages · Page 1 of 1 (latest)

whole tinsel
#

I put my extensions in a folder structure like this

|--exts
|  |--fun
|      |--__init__.py
|      |--fun1.py
|      |--fun2.py

In the __init__.py file, I write this:

import logging
import interactions
from src.const import EXT_FUN


class Fun(interactions.Extension):
    """exts/fun Extension."""

    def __init__(self, client: interactions.Client) -> None:
        self.client: interactions.Client = client
        for ext in EXT_FUN:
            try:
                self.client.load_extension(f"src.exts.fun.{ext}")
            except interactions.errors.ExtensionLoadException:
                logging.critical(f"src.exts.fun.{ext} failed to loaded.")
                pass


def setup(client) -> None:
    """Setup the extension"""
    Fun(client)
    logging.info("Loaded Fun extension.")

The problem here is, if fun1.py has an error, instead of passing it and continue loading fun2.py, it stops here. How to pass the fun1.py error file and continue loading the fun2.py file?

leaden boughBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

whole tinsel
#

Any help?

stoic umbra
#

im not sure because that should be working 😅

whole tinsel
#

I have no idea why.

#

Like, I force it to be ValueError, AttributeError or whatsoever.

#

Such as removing a comma, indent, etc.

narrow urchin
#

have you tried using sys.path.append()? it might not be finding the files when attempting to import

#

you can do ('..') , ('.') or even (os.getcwd())

#

path would need to be appended before loading calls

stoic umbra
#

im more curious about what the errors are in the first place

narrow urchin
#

maybe if we passed error details instead of an exception name we'd know