def _post_mortem(entry_file): '''Returns restart value: True, False, or None.''' vimpdb = VimPdb(def_colors) vimpdb.reset() vimpdb._user_requested_quit = 0 etype, value, tb = sys.exc_info() # attempt to import and use colorization from rednose try: from rednose import RedNose ftb = RedNose()._fmt_traceback(tb) ftb = ftb.split('\n') ftb.append('') ex_line = red(traceback.format_exception_only(etype, value)[0]) ftb.append(ex_line) except ImportError: ftb = traceback.format_exception(etype, value, tb) ftb = ''.join(ftb) ftb = ftb.split('\n') # save the header line and the file entry point filename = os.path.basename(entry_file) while filename not in ftb[1]: try: ftb.pop(1) except IndexError: break if len(ftb) == 1: break ftb.insert(1, ' ...') print print red(_line_str('EXCEPTION')) print '\n'.join(ftb) print print red(_line_str('BEGIN POST-MORTEM')) try: vimpdb.interaction(None, tb) if vimpdb._user_requested_quit: raise BdbQuit() finally: print red(_line_str('END POST-MORTEM'))
def test_entrypoint_bdb_quit(mocker): mocker.patch('jenkins_epo.script.logging') from jenkins_epo.script import entrypoint from bdb import BdbQuit main = mocker.patch('jenkins_epo.main.main') CACHE = mocker.patch('jenkins_epo.cache.CACHE') main.side_effect = BdbQuit() with pytest.raises(SystemExit): entrypoint() assert CACHE.close.mock_calls
def interaction(self, frame, tb=None, exception='Wdb', exception_description='Set Trace'): """Entry point of user interaction""" if not self.ws: raise BdbQuit() try: self._interaction(frame, tb, exception, exception_description) except WsError: log.exception('Websocket Error during interaction. Starting again') self.handle_connection() # Recursive call to restart interaction on ws crash self.interaction(frame, tb, exception, exception_description)
def main(app, argv, environ): raise BdbQuit()
def run(runner, msgs, entry_file): ''' Main loop used for debuging. sys.exit(0) - immediately end sys.exit(1) - allow read of error then end sys.exit(2) - prompt for repeat sys.exit(3) - repeat ''' (header_msg, exc_msg, end_msg) = msgs line = blue(_line_str()) print line print header_msg print line vimpdb = VimPdb(def_colors) vimpdb._user_requested_quit = False restart = None try: runner(vimpdb) if vimpdb._user_requested_quit: raise BdbQuit() except BdbQuit: restart = False except Restart: restart = True except SystemExit: code = sys.exc_info()[1] print blue('Exited with sys.exit(%s).' % code) except: try: _post_mortem(entry_file) except BdbQuit: restart = False except Restart: restart = True if len(exc_msg) > 0: print '\n' + exc_msg else: if len(end_msg) > 0: print '\n' + end_msg finally: print line if restart is None: # unknown request sys.exit(4) else: if restart: # restart request sys.exit(3) else: # quit request sys.exit(0)