Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _debug_on_error(context, step):
if context.config.userdata.getbool("debug"):
try:
import ipdb
ipdb.post_mortem(step.exc_traceback)
except ImportError:
import pdb
pdb.post_mortem(step.exc_traceback)
eyed3.utils.console.printError(f"Uncaught exception: {ex}\n")
eyed3.log.exception(ex)
retval = 1
if args.debug_pdb:
try:
with warnings.catch_warnings():
warnings.simplefilter("ignore", PendingDeprecationWarning)
# Must delay the import of ipdb as say as possible because
# of https://github.com/gotcha/ipdb/issues/48
import ipdb as pdb # noqa
except ImportError:
import pdb # noqa
e, m, tb = sys.exc_info()
pdb.post_mortem(tb)
sys.exit(retval)
and not ui.pageractive
and not ui.plain()
and ui.formatted()
):
ui.write_err(
_(
"Starting ipdb for this exception\nIf you don't want the behavior, set devel.debugger to False\n"
)
)
with demandimport.deactivated():
import ipdb
if not ui.tracebackflag:
traceback.print_exc()
ipdb.post_mortem(sys.exc_info()[2])
os._exit(255)
if not handlecommandexception(ui):
raise
return -1
"""This wraps the main method of an action so that:
- backtrace is not printed by default
- backtrace is printed is --backtrace was given
- a pdb session is run if --pdb was given
"""
try:
module.do(args)
except Exception as e:
if args.pdb:
traceback = sys.exc_info()[2]
print ""
print "### Exception:", e
print "### Starting a debugger"
try:
import ipdb
ipdb.post_mortem(traceback)
sys.exit(0)
except ImportError:
import pdb
pdb.post_mortem(traceback)
sys.exit(0)
if args.backtrace:
raise
logger = logging.getLogger("\n") # small hack
logger.error(str(e))
sys.exit(2)
debugtrace[debugger]()
try:
return _dispatch(req)
finally:
ui.flush()
except: # re-raises
# Potentially enter the debugger when we hit an exception
startdebugger = req.earlyoptions["debugger"]
if startdebugger:
# Enforce the use of ipdb, since it's always available and
# we can afford the import overhead here.
with demandimport.deactivated():
import ipdb
traceback.print_exc()
ipdb.post_mortem(sys.exc_info()[2])
os._exit(255)
raise
debugtrace[debugger]()
try:
return _dispatch(req)
finally:
ui.flush()
except: # re-raises
# Potentially enter the debugger when we hit an exception
startdebugger = req.earlyoptions["debugger"]
if startdebugger:
# Enforce the use of ipdb, since it's always available and
# we can afford the import overhead here.
with demandimport.deactivated():
import ipdb
traceback.print_exc()
ipdb.post_mortem(sys.exc_info()[2])
os._exit(255)
raise
def __exit__(self, e, m, tb):
if not e:
return
try:
import ipdb as pdb
except ImportError:
import pdb
print(m.__repr__(), file=sys.stderr)
pdb.post_mortem(tb)
def exception_handler(type, value, traceback):
click.secho(
'\nAn exception occurred while executing the requested '
'command:', fg='red'
)
hr(fg='red')
sys.__excepthook__(type, value, traceback)
click.secho('\nStarting interactive debugging session:', fg='red')
hr(fg='red')
pdb.post_mortem(traceback)
sys.excepthook = exception_handler
def new_hook(typ, value, tb):
old_hook(typ, value, tb)
if typ != KeyboardInterrupt:
import ipdb
ipdb.post_mortem(tb)
def debug(self):
import ipdb
ipdb.post_mortem(self.traceback)