better error handling in checkup

pull/1/head
ansuz 3 years ago
parent e5df9cb730
commit 83119a25c8

@ -6,7 +6,35 @@ define([], function () {
var MESSAGES = [];
var assert = function (test, msg) {
MESSAGES.push(msg || false);
ASSERTS.push(function (cb, i) {
ASSERTS.push(function (_cb, i) {
var called = false;
var to;
var cb = function (arg) {
if (to) {
clearTimeout(to);
to = undefined;
}
if (called) { return; }
called = true;
_cb(arg);
};
var _msg = document.createElement('span');
_msg.innerText = "An unexpected error occurred. See your browser's console for more details";
if (msg && !msg.innerText) {
msg.innerText = _msg.innerText;
}
to = setTimeout(function () {
cb({
test: i,
message: msg || _msg,
output: "TIMEOUT",
});
}, 25000);
try {
test(function (result) {
if (result === true) {
passed++;
@ -14,11 +42,29 @@ define([], function () {
} else {
cb({
test: i,
message: msg,
message: msg || _msg,
output: result,
});
}
}, msg);
} catch (err) {
console.error(err);
msg.innerText = `Synchronous error thrown (${(err.message || err)}). See console for more details.`;
//from ${err.fileName} line ${err.lineNumber}`;
cb({
test: i,
message: msg || _msg,
output: {
message: err.message,
file: err.fileName,
line: err.lineNumber,
stack: typeof(err.stack) === 'string'?
err.stack.split('\n'):
err.stack,
},
});
}
});
};

@ -1,4 +1,15 @@
(function () {
var h = (tag, children) => {
var el = document.createElement(tag);
children.forEach(child => {
if (typeof(child) === 'string') {
return void el.appendChild(document.createTextNode(child));
}
el.appendChild(child);
});
return el;
};
var first = true;
window.addEventListener('error', function (ev) {
if (!ev) { return; }
@ -7,11 +18,25 @@
var nodeName = srcElement.nodeName;
if (nodeName !== 'SCRIPT') { return; }
var src = srcElement.src;
if (!/\/bower_components\/.*/.test(src)) { return; }
if (/\/api\/.*/.test(src)) {
console.error("A serverside API endpoint could not be reached.", src);
}
//if (!/\/bower_components\/.*/.test(src)) { return; }
if (first) {
document.write(`<p>It's possible that this server's administrators forgot to install its client-side dependencies with 'bower update'.</p>`);
document.body.appendChild(h('h1', ['Oops!']));
document.body.appendChild(h('p', [
`It's possible that this server's administrators forgot to install its client-side dependencies with 'bower update',`,
` or that some other required resource couldn't be loaded.`,
` See your browser's console for more details.`,
]));
first = false;
}
document.write(`<p>Failed to load <code>${src}</code>.</p>`);
document.body.appendChild(h('p', [
'Failed to load ',
h('code', [src]),
'.',
]));
}, true);
}());

@ -3,10 +3,10 @@
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script type="text/javascript" src="/checkup/dependency-warning.js?ver=1.0.0"></script>
<script data-bootload="main.js" data-main="/common/boot.js" src="/bower_components/requirejs/require.js"></script>
</head>
<body>
<div id="cp-progress"></div>
<iframe-placeholder>
<script type="text/javascript" src="/checkup/dependency-warning.js?ver=1.0.0"></script>
<script data-bootload="main.js" data-main="/common/boot.js" src="/bower_components/requirejs/require.js"></script>

Loading…
Cancel
Save