|
17 | 17 | from ansi2html import Ansi2HTMLConverter
|
18 | 18 | import uuid
|
19 | 19 |
|
| 20 | +from .comms import _dash_comm, _jupyter_config, _request_jupyter_config |
20 | 21 |
|
21 | | -from werkzeug.debug.tbtools import get_current_traceback |
22 | 22 |
|
23 | | -from .comms import _dash_comm, _jupyter_config, _request_jupyter_config |
| 23 | +def _get_skip(error: Exception, divider=2): |
| 24 | + |
| 25 | + try: |
| 26 | + # pylint: disable=import-outside-toplevel |
| 27 | + from werkzeug.debug import tbtools |
| 28 | + except ImportError: |
| 29 | + tbtools = None |
| 30 | + |
| 31 | + # werkzeug<2.1.0 |
| 32 | + if hasattr(tbtools, "get_current_traceback"): |
| 33 | + tb = tbtools.get_current_traceback() |
| 34 | + text = tb.plaintext.splitlines() |
| 35 | + |
| 36 | + if hasattr(tbtools, "DebugTraceback"): |
| 37 | + tb = tbtools.DebugTraceback(error) # pylint: disable=no-member |
| 38 | + text = tb.render_traceback_text().splitlines() |
| 39 | + |
| 40 | + skip = 0 |
| 41 | + for i, line in enumerate(text): |
| 42 | + if "%% callback invoked %%" in line: |
| 43 | + skip = int((i + 1) / divider) |
| 44 | + break |
| 45 | + return skip |
24 | 46 |
|
25 | 47 |
|
26 | 48 | class JupyterDash(dash.Dash):
|
@@ -356,18 +378,12 @@ def _config_callback_exception_handling(
|
356 | 378 | ):
|
357 | 379 |
|
358 | 380 | @self.server.errorhandler(Exception)
|
359 | | - def _wrap_errors(_): |
| 381 | + def _wrap_errors(error): |
360 | 382 | """Install traceback handling for callbacks"""
|
361 | 383 | self._traceback = sys.exc_info()[2]
|
362 | 384 |
|
363 | 385 | # Compute number of stack frames to skip to get down to callback
|
364 | | - tb_werkzeug = get_current_traceback() |
365 | | - skip = 0 |
366 | | - if dev_tools_prune_errors: |
367 | | - for i, line in enumerate(tb_werkzeug.plaintext.splitlines()): |
368 | | - if "%% callback invoked %%" in line: |
369 | | - skip = int((i + 1) / 2) |
370 | | - break |
| 386 | + skip = _get_skip(error) if dev_tools_prune_errors else 0 |
371 | 387 |
|
372 | 388 | # Customized formatargvalues function so we can place function parameters
|
373 | 389 | # on separate lines
|
|
0 commit comments