Skip to content

Commit

Permalink
Merge pull request OpenMined#9273 from OpenMined/aziz/traceback_url
Browse files Browse the repository at this point in the history
make traceback clickable
  • Loading branch information
koenvanderveen authored Sep 5, 2024
2 parents 7274cfa + e8d43de commit eed018e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
60 changes: 36 additions & 24 deletions packages/syft/src/syft/assets/jinja/syft_exception.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,47 @@
</span>
</summary>
<div id="{{html_id}}" class="syft-exception-dropdown">
{% if server_trace%}
<div><strong>Server Trace:</strong></div>
<pre class="syft-exception-trace">{{server_trace | escape}}</pre>
<br>
<br>
{% if server_trace %}
<div><strong>Server Trace:</strong></div>
<pre class="syft-exception-trace">
{% if dev_mode %}
{{ server_trace | make_links | safe }}
{% else %}
{{ server_trace | escape }}
{% endif %}
<div><strong>Client Trace:</strong></div>
<pre class="syft-exception-trace">{{traceback_str | escape}}</pre>
</pre>
<br>
<br>
{% endif %}
<div><strong>Client Trace:</strong></div>
<pre class="syft-exception-trace">
{% if dev_mode %}
{{ traceback_str | make_links | safe }}
{% else %}
{{ traceback_str | escape }}
{% endif %}
</pre>
</div>
</details>

<style>
.syft-exception-summary {
padding: 5px;
cursor: pointer;
}
.syft-exception-summary {
padding: 5px;
cursor: pointer;
}
.syft-exception-message {
display: inline;
font-family: inherit;
}
.syft-exception-message {
display: inline;
font-family: inherit;
}
.syft-exception-dropdown {
margin-top: 5px;
padding: 10px;
border-top: 1px solid #ccc;
}
.syft-exception-dropdown {
margin-top: 5px;
padding: 10px;
border-top: 1px solid #ccc;
}
.syft-exception-trace {
display: inline;
}
</style>
.syft-exception-trace {
display: inline;
}
</style>
1 change: 1 addition & 0 deletions packages/syft/src/syft/types/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def _repr_html_(self) -> str:
message=self._private_message or self.public,
traceback_str=traceback_str,
display=display,
dev_mode=is_dev_mode,
)
return table_html

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# stdlib
import json
import logging
import re
import secrets
from typing import Any

Expand All @@ -20,8 +21,15 @@

logger = logging.getLogger(__name__)


def make_links(text: str) -> str:
file_pattern = re.compile(r"([\w/.-]+\.py)\", line (\d+)")
return file_pattern.sub(r'<a href="file://\1#L\2">\1, line \2</a>', text)


DEFAULT_ID_WIDTH = 110
jinja_env = jinja2.Environment(loader=jinja2.PackageLoader("syft", "assets/jinja")) # nosec
jinja_env.filters["make_links"] = make_links


def create_tabulator_columns(
Expand Down

0 comments on commit eed018e

Please sign in to comment.