import pprint


def format_locals(sys_exc_info):
    """Format locals for the frame where exception was raised."""

    current_tb = sys_exc_info[-1]
    while current_tb:
        next_tb = current_tb.tb_next
        if not next_tb:
            frame_locals = current_tb.tb_frame.f_locals
            return pprint.pformat(frame_locals)
        current_tb = next_tb