from typing import List
import traceback


def catch_errors_as_message(function):
    """Catches errors as a list of messages

    Parameters
    ----------
    function : Coroutine[Any, Any, List[str]]
        Function to wrap. In case of an error
        the message is returned.
    """

    async def wrapper(*args, **kwargs) -> List[str]:
        try:
            return await function(*args, **kwargs)
        except Exception:
            trace = traceback.format_exc()
            return [trace]

    return wrapper