diff --git a/IPython/core/application.py b/IPython/core/application.py index 64656e4..4b49a94 100644 --- a/IPython/core/application.py +++ b/IPython/core/application.py @@ -137,6 +137,11 @@ class BaseIPythonApplication(Application): profile, then they will be staged into the new directory. Otherwise, default config files will be automatically generated. """) + + verbose_crash = Bool(False, config=True, + help="""Create a massive crash report when IPython enconters what may be an + internal error. The default is to append a short message to the + usual traceback""") # The class to use as the crash handler. crash_handler_class = Type(crashhandler.CrashHandler) @@ -154,11 +159,23 @@ class BaseIPythonApplication(Application): def init_crash_handler(self): """Create a crash handler, typically setting sys.excepthook to it.""" self.crash_handler = self.crash_handler_class(self) - sys.excepthook = self.crash_handler + sys.excepthook = self.excepthook def unset_crashhandler(): sys.excepthook = sys.__excepthook__ atexit.register(unset_crashhandler) - + + def excepthook(self, etype, evalue, tb): + """this is sys.excepthook after init_crashhandler + + set self.verbose_crash=True to use our full crashhandler, instead of + a regular traceback with a short message (crash_handler_lite) + """ + + if self.verbose_crash: + return self.crash_handler(etype, evalue, tb) + else: + return crashhandler.crash_handler_lite(etype, evalue, tb) + def _ipython_dir_changed(self, name, old, new): if old in sys.path: sys.path.remove(old) diff --git a/IPython/core/crashhandler.py b/IPython/core/crashhandler.py index 0774ac2..3d509da 100644 --- a/IPython/core/crashhandler.py +++ b/IPython/core/crashhandler.py @@ -21,9 +21,11 @@ Authors: import os import sys +import traceback from pprint import pformat from IPython.core import ultratb +from IPython.core.release import author_email from IPython.utils.sysinfo import sys_info #----------------------------------------------------------------------------- @@ -54,6 +56,15 @@ To ensure accurate tracking of this issue, please file a report about it at: {bug_tracker} """ +_lite_message_template = """ +If you suspect this is an IPython bug, please report it at: + https://github.com/ipython/ipython/issues +or send an email to the mailing list at {email} + +You can enable a much more verbose traceback with: + {config}Application.verbose_crash=True +""" + class CrashHandler(object): """Customizable crash handlers for IPython applications. @@ -161,7 +172,7 @@ class CrashHandler(object): # Construct report on disk report.write(self.make_report(traceback)) report.close() - raw_input("Hit to quit this message (your terminal may close):") + raw_input("Hit to quit (your terminal may close):") def make_report(self,traceback): """Return a string containing a crash report.""" @@ -184,3 +195,17 @@ class CrashHandler(object): return ''.join(report) + +def crash_handler_lite(etype, evalue, tb): + """a light excepthook, adding a small message to the usual traceback""" + traceback.print_exception(etype, evalue, tb) + + from IPython.core.interactiveshell import InteractiveShell + if InteractiveShell.initialized(): + # we are in a Shell environment, give %magic example + config = "%config " + else: + # we are not in a shell, show generic config + config = "c." + print >> sys.stderr, _lite_message_template.format(email=author_email, config=config) +