Skip to content

Commit

Permalink
Plug Debugger add ability to wrap exception text
Browse files Browse the repository at this point in the history
Sometimes exceptions print out with really long lines which makes it
difficult to read the exceptions on the error page.

This PR adds a "Wrap text?" checkbox that toggles wrapping on the
exception details.
  • Loading branch information
axelson committed Aug 24, 2024
1 parent 7b14af2 commit 27a7646
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/plug/templates/debugger.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,14 @@
.exception-info > code {
line-height: 1.5;
font-size: <%= :math.pow(1.3, -1) %>em;
}
.wrap-text-checkbox-container {
display: flex;
gap: 6px;
}
/*
* Code explorer
*/
Expand Down Expand Up @@ -574,6 +580,10 @@
margin: 0;
}
.code-quote > li {
padding: 6px 0;
}
.code.-padded {
padding: 0 16px 16px 16px;
}
Expand Down Expand Up @@ -676,7 +686,10 @@
<small>at <%= h method(@conn) %></small>
<small class="path"><%= h @conn.request_path %></small>
</h5>
<code><pre><%= h @message %></pre></code>
<code><pre role="exception-details-text"><%= h @message %></pre></code>
<div class="wrap-text-checkbox-container">
<input role="wrap-text-checkbox" type="checkbox" value="wrap_text">Wrap text?
</div>
</header>

<%= for %{label: label, encoded_handler: encoded_handler} <- @actions do %>
Expand Down Expand Up @@ -836,16 +849,27 @@
var $copyBtn = document.querySelector('[role~="copy-to-markdown"]')
var $copyBtnText = document.querySelector('[role~="copy-to-markdown-text"]')
var $copy = document.querySelector('[role~="copy-contents"]')
var $exceptionDetailsText = document.querySelector('[role~="exception-details-text"]')
var $wrapTextCheckbox = document.querySelector('[role~="wrap-text-checkbox"]')
each($items, function ($item) {
on($item, 'click', itemOnclick)
})
on($toggle, 'click', toggleOnclick)
on($copyBtn, 'click', copyToClipboard)
on($wrapTextCheckbox, 'click', toggleWrapExceptionText)
restoreToggle()
function toggleWrapExceptionText () {
if ($exceptionDetailsText.style.whiteSpace === 'pre-wrap') {
$exceptionDetailsText.style.whiteSpace = '';
} else {
$exceptionDetailsText.style.whiteSpace = 'pre-wrap';
}
}
function copyToClipboard () {
if(navigator.clipboard) {
// For those working on localhost or HTTPS
Expand Down

0 comments on commit 27a7646

Please sign in to comment.