import traceback


def exception_to_string(raised_exception):
    """Reformat an exception to string

    The default __repr__ for exceptions strips away the traceback information. This
    is fine for logging as it accepts the exc_info flag. Normal formatting `str(exception)`
    doesn't support that. This formatter ensures the full stacktrace is returned an not just
    the exception text.

    Args:
        raised_exception (Exception): Exception to format

    Returns:
        message (str): Representation of the exception as a string with traceback

    Examples:
        >>> exception_to_string(RuntimeError("Well this happend"))

            File "somefile.py", line 1443, in test_exception_to_string
                raise RuntimeError("Well, this happend")
    """
    try:
        msg = f"{type(raised_exception)}: {raised_exception}\n\n"
    except AttributeError:
        msg = ""

    try:
        msg += "\n".join(traceback.format_tb(raised_exception.__traceback__))
    except Exception:
        # Fallback to default formatting if traceback isn't available
        msg += str(raised_exception)
    return msg