|
9 | 9 | import re |
10 | 10 | import sys |
11 | 11 | import inspect |
| 12 | +import traceback |
12 | 13 | import warnings |
13 | 14 |
|
14 | 15 | from IPython import get_ipython |
|
17 | 18 | from ansi2html import Ansi2HTMLConverter |
18 | 19 | import uuid |
19 | 20 |
|
| 21 | +from .comms import _dash_comm, _jupyter_config, _request_jupyter_config |
20 | 22 |
|
21 | | -from werkzeug.debug.tbtools import get_current_traceback |
22 | 23 |
|
23 | | -from .comms import _dash_comm, _jupyter_config, _request_jupyter_config |
| 24 | +def _get_skip(error: Exception): |
| 25 | + tb = traceback.format_exception(type(error), error, error.__traceback__) |
| 26 | + skip = 0 |
| 27 | + for i, line in enumerate(text): |
| 28 | + if "%% callback invoked %%" in line: |
| 29 | + skip = i + 1 |
| 30 | + break |
| 31 | + return skip |
24 | 32 |
|
25 | 33 |
|
26 | 34 | class JupyterDash(dash.Dash): |
@@ -356,18 +364,12 @@ def _config_callback_exception_handling( |
356 | 364 | ): |
357 | 365 |
|
358 | 366 | @self.server.errorhandler(Exception) |
359 | | - def _wrap_errors(_): |
| 367 | + def _wrap_errors(error): |
360 | 368 | """Install traceback handling for callbacks""" |
361 | 369 | self._traceback = sys.exc_info()[2] |
362 | 370 |
|
363 | 371 | # 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 |
| 372 | + skip = _get_skip(error) if dev_tools_prune_errors else 0 |
371 | 373 |
|
372 | 374 | # Customized formatargvalues function so we can place function parameters |
373 | 375 | # on separate lines |
|
0 commit comments