MCPcopy Index your code
hub / github.com/plotly/dash / format_traceback_html

Function format_traceback_html

dash/backends/_utils.py:5–108  ·  view source on GitHub ↗
(error, error_handling_mode, title, backend)

Source from the content-addressed store, hash-verified

3
4
5def format_traceback_html(error, error_handling_mode, title, backend):
6 tb = error.__traceback__
7 errors = traceback.format_exception(type(error), error, tb)
8 pass_errs = []
9 callback_handled = False
10 for err in errors:
11 if error_handling_mode == "prune":
12 if not callback_handled:
13 if "callback invoked" in str(err) and "_callback.py" in str(err):
14 callback_handled = True
15 continue
16 pass_errs.append(err)
17 formatted_tb = "".join(pass_errs)
18 error_type = type(error).__name__
19 error_msg = str(error)
20 # Parse traceback lines to group by file
21 file_cards = []
22 pattern = re.compile(r' File "(.+)", line (\d+), in (\w+)')
23 lines = formatted_tb.split("\n")
24 current_file = None
25 card_lines = []
26 for line in lines[:-1]: # Skip the last line (error message)
27 match = pattern.match(line)
28 if match:
29 if current_file and card_lines:
30 file_cards.append((current_file, card_lines))
31 current_file = (
32 f"{match.group(1)} (line {match.group(2)}, in {match.group(3)})"
33 )
34 card_lines = [line]
35 elif current_file:
36 card_lines.append(line)
37 if current_file and card_lines:
38 file_cards.append((current_file, card_lines))
39 cards_html = ""
40 for filename, card in file_cards:
41 cards_html += (
42 f"""
43 <div class=\"error-card\">
44 <div class=\"error-card-header\">{filename}</div>
45 <pre class=\"error-card-traceback\">"""
46 + "\n".join(card)
47 + """</pre>
48 </div>
49 """
50 )
51 html = f"""
52 <!doctype html>
53 <html lang=\"en\">
54 <head>
55 <title>{error_type}: {error_msg} // {title}</title>
56 <style>
57 body {{ font-family: monospace; background: #fff; color: #333; }}
58 .debugger {{ margin: 2em; max-width: 700px; }}
59 .error-card {{
60 border: 1px solid #ccc;
61 border-radius: 6px;
62 margin-bottom: 1em;

Callers 2

_get_tracebackMethod · 0.85
_get_tracebackMethod · 0.85

Calls 4

compileMethod · 0.80
appendMethod · 0.45
matchMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…