Skip to content

Send error message without context from command #9990

Closed Answered by Drakan1
Drakan1 asked this question in Q&A
Discussion options

You must be logged in to vote

I solved it by using the frame stack:

def _get_frame_context(self, logger=None):
    """Inspect the stack to find the context object from invoke"""
    frame_stack = inspect_stack()
    for frame_info in frame_stack:
        if frame_info.function.lower() == "invoke":
            context = frame_info.frame.f_locals["ctx"]
            break
    else:
        logger = self.logger if not logger else logger
        raise CommandError("Could not find context object", logger)
    del frame_stack
    return context

async def send_error(self, message: str, logger: logging.Logger, context=None):
    """
    :param message: The error message
    :param logger: The logger from where the error occured

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Soheab
Comment options

@Drakan1
Comment options

Answer selected by Drakan1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants