#NEWLINE# @ contextlib . contextmanager #NEWLINE# def format_exceptions( debug = False , pdb = False , start_time = None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( yield ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# if debug : #NEWLINE# #INDENT# traceback . print_exc ( ) #NEWLINE# if pdb : #NEWLINE# #INDENT# import pdb #NEWLINE# pdb . post_mortem ( e . __traceback__ ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# stack = traceback . extract_tb ( e . __traceback__ ) #NEWLINE# last = [ i for i in stack if ( 'calliope' in i [ 0 ] ) ] [ ( - 1 ) ] #NEWLINE# if debug : #NEWLINE# #INDENT# err_string = '\nError in {}, {}:{}' . format ( debug [ 2 ] , last [ 0 ] , last [ 1 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# err_string = '\nError in {}:' . format ( last [ 2 ] ) #NEWLINE# #UNINDENT# click . secho ( err_string , fg = 'red' ) #NEWLINE# click . secho ( str ( e ) , fg = 'red' ) #NEWLINE# if start_time : #NEWLINE# #INDENT# print_end_time ( start_time , msg = 'aborted due to an error' ) #NEWLINE# #UNINDENT# #UNINDENT# sys . exit ( 1 )