Skip to content

Commit

Permalink
add debug link button on exception page (shows error if a debug link …
Browse files Browse the repository at this point in the history
…cannot be made)
  • Loading branch information
tadhgboyle committed Oct 28, 2021
1 parent f652769 commit 4f9a76a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
5 changes: 2 additions & 3 deletions error.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
* Error page
*/

// TODO: add debug link button, will need to add regex check to url after ajax get(),
// if it is not valid debug link url, show an error and red X

if (!defined('ERRORHANDLER')) {
die();
}
Expand Down Expand Up @@ -57,6 +54,8 @@
'ERROR_TYPE' => is_null($exception) ? $language->get('general', 'error') : (new ReflectionClass($exception))->getName(),
'ERROR_STRING' => $error_string,
'ERROR_FILE' => $error_file,
'DEBUG_LINK' => $language->get('admin', 'debug_link'),
'DEBUG_LINK_URL' => URL::build('/queries/debug_link'),
'ERROR_SQL_STACK' => QueryRecorder::getInstance()->getSqlStack(),
'CURRENT_URL' => $current_url,
'FRAMES' => $frames,
Expand Down
45 changes: 45 additions & 0 deletions error.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@
<h3>(File: {$ERROR_FILE})</h3>
<a href="{$CURRENT_URL}">{$CURRENT_URL}</a>

<button class="float-right btn btn-info d-flex align-items-center" id="debug_link">
<span class="spinner-border spinner-border-sm mr-2" role="status" id="debug_link_loading" style="display: none;"></span>
<span id="debug_link_text">{$DEBUG_LINK}</span>
<span id="debug_link_success" style="display: none;">
<i class="fa fa-check"></i>
</span>
<span id="debug_link_error" style="display: none;">
<i class="fa fa-times-circle"></i>
</span>
</button>

{else}

<h2>{$FATAL_ERROR_TITLE}</h2>
Expand Down Expand Up @@ -270,6 +281,40 @@ function openSqlFrame(id) {
$('#sql-frame-' + id).css('display', 'block');
$('#sql-button-' + id).addClass('active');
}
let link_created = false;
$('#debug_link').click(() => {
$('#debug_link').blur();
if (link_created) {
return;
}
$('#debug_link').prop('disabled', true);
$('#debug_link_loading').show(100);
$.get('{$DEBUG_LINK_URL}')
.done((url) => {
link_created = true;
$('#debug_link_loading').hide(100);
$('#debug_link').removeClass('btn-info');
$('#debug_link_text').hide();
$('#debug_link').prop('disabled', false);
if (!url.startsWith('https://debug.namelessmc.com/')) {
$('#debug_link').addClass('btn-danger');
$('#debug_link_error').show();
console.log(url);
alert('Could not create debug link. Check console for information.');
} else {
navigator.clipboard.writeText(url);
$('#debug_link').addClass('btn-success');
$('#debug_link_success').show();
alert('Copied debug link to your clipboard.');
}
});
});
</script>
</html>

0 comments on commit 4f9a76a

Please sign in to comment.