import traceback
import re


def format_traceback(trace = ''):
    """Format traceback message.

    Parameters
    ----------
    trace : str
        Traceback to format. Defaults to `traceback.format_exc()`.

    Notes
    -----
    Format trackback for readability to pass into user messages. 

    Returns
    -------
    formatted : str
        Formatted traceback.
    """
    
    if not trace:
        trace = traceback.format_exc()

    trace = '\n' + trace.strip()
    formatted = re.sub('\n', '\n  > ', trace)

    return(formatted)