def handle_exception(app: Sphinx, args: Any, exception: BaseException, stderr: IO = sys.stderr) -> None: # NOQA if isinstance(exception, bdb.BdbQuit): return if args.pdb: print(red(__('Exception occurred while building, starting debugger:')), file=stderr) traceback.print_exc() pdb.post_mortem(sys.exc_info()[2]) else: print(file=stderr) if args.verbosity or args.traceback: traceback.print_exc(None, stderr) print(file=stderr) if isinstance(exception, KeyboardInterrupt): print(__('Interrupted!'), file=stderr) elif isinstance(exception, SystemMessage): print(red(__('reST markup error:')), file=stderr) print(terminal_safe(exception.args[0]), file=stderr) elif isinstance(exception, SphinxError): print(red('%s:' % exception.category), file=stderr) print(str(exception), file=stderr) elif isinstance(exception, UnicodeError): print(red(__('Encoding error:')), file=stderr) print(terminal_safe(str(exception)), file=stderr) tbpath = save_traceback(app) print(red( __('The full traceback has been saved in %s, if you want ' 'to report the issue to the developers.') % tbpath), file=stderr) elif isinstance(exception, RuntimeError) and 'recursion depth' in str(exception): print(red(__('Recursion error:')), file=stderr) print(terminal_safe(str(exception)), file=stderr) print(file=stderr) print(__('This can happen with very large or deeply nested source ' 'files. You can carefully increase the default Python ' 'recursion limit of 1000 in conf.py with e.g.:'), file=stderr) print(' import sys; sys.setrecursionlimit(1500)', file=stderr) else: print(red(__('Exception occurred:')), file=stderr) print(format_exception_cut_frames().rstrip(), file=stderr) tbpath = save_traceback(app) print(red( __('The full traceback has been saved in %s, if you ' 'want to report the issue to the developers.') % tbpath), file=stderr) print(__('Please also report this if it was a user error, so ' 'that a better error message can be provided next time.'), file=stderr) print(__('A bug report can be filed in the tracker at ' '<https://github.com/sphinx-doc/sphinx/issues>. Thanks!'), file=stderr)
def handle_exception(app, args, exception, stderr=sys.stderr): # type: (Sphinx, Any, Union[Exception, KeyboardInterrupt], IO) -> None if args.pdb: import pdb print(red(__('Exception occurred while building, starting debugger:')), file=stderr) traceback.print_exc() pdb.post_mortem(sys.exc_info()[2]) else: print(file=stderr) if args.verbosity or args.traceback: traceback.print_exc(None, stderr) print(file=stderr) if isinstance(exception, KeyboardInterrupt): print(__('interrupted!'), file=stderr) elif isinstance(exception, SystemMessage): print(red(__('reST markup error:')), file=stderr) print(terminal_safe(exception.args[0]), file=stderr) elif isinstance(exception, SphinxError): print(red('%s:' % exception.category), file=stderr) print(terminal_safe(str(exception)), file=stderr) elif isinstance(exception, UnicodeError): print(red(__('Encoding error:')), file=stderr) print(terminal_safe(str(exception)), file=stderr) tbpath = save_traceback(app) print(red(__('The full traceback has been saved in %s, if you want ' 'to report the issue to the developers.') % tbpath), file=stderr) elif isinstance(exception, RuntimeError) and 'recursion depth' in str(exception): print(red(__('Recursion error:')), file=stderr) print(terminal_safe(str(exception)), file=stderr) print(file=stderr) print(__('This can happen with very large or deeply nested source ' 'files. You can carefully increase the default Python ' 'recursion limit of 1000 in conf.py with e.g.:'), file=stderr) print(__(' import sys; sys.setrecursionlimit(1500)'), file=stderr) else: print(red(__('Exception occurred:')), file=stderr) print(format_exception_cut_frames().rstrip(), file=stderr) tbpath = save_traceback(app) print(red(__('The full traceback has been saved in %s, if you ' 'want to report the issue to the developers.') % tbpath), file=stderr) print(__('Please also report this if it was a user error, so ' 'that a better error message can be provided next time.'), file=stderr) print(__('A bug report can be filed in the tracker at ' '<https://github.com/sphinx-doc/sphinx/issues>. Thanks!'), file=stderr)