From 21a064343436bb1f324dc8fea74b0af8875e8fce Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Tue, 17 Nov 2009 12:50:21 +0000 Subject: Added error reporter sending back code on faulty load --- itjs/0.gif | Bin 0 -> 43 bytes itjs/boot.js | 81 +++++++++++++++++++++++++++++++++++++++++++-------------- itjs/error.gif | Bin 43 -> 0 bytes 3 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 itjs/0.gif delete mode 100644 itjs/error.gif (limited to 'itjs') diff --git a/itjs/0.gif b/itjs/0.gif new file mode 100644 index 0000000..5bfd67a Binary files /dev/null and b/itjs/0.gif differ diff --git a/itjs/boot.js b/itjs/boot.js index 8a2a30a..0d9a737 100644 --- a/itjs/boot.js +++ b/itjs/boot.js @@ -1,10 +1,10 @@ // $Id$ var it_boot_status = "boot"; -var it_panictimer = window.setTimeout("it_panic(it_boot_status)", 31337), it_domtimer; +var it_panictimer = window.setTimeout("it_panic({reason:it_boot_status})", 31337), it_domtimer; var it_starttime = new Date().getTime(); -function it_catcherr(msg, url, line) +function it_stacktrace() { var stacktrace = ""; var callstack_done = false; @@ -31,7 +31,7 @@ function it_catcherr(msg, url, line) entry += " at " + lines[i+1]; i++; } - stacktrace += entry + '/'; + stacktrace += entry + ','; } } callstack_done = true; @@ -44,11 +44,18 @@ function it_catcherr(msg, url, line) while (current_func) { fname = /function\s*([\w\-$]+)?\s*\(/.test(current_func.toString()) ? RegExp.$1 || 'anonymous' : 'anonymous'; - stacktrace += fname + '/'; + stacktrace += fname + ','; current_func = current_func.caller; } } + return stacktrace; +} + +function it_catcherr(msg, url, line) +{ + var stacktrace = it_stacktrace(); + if (typeof it_boot.sequence != 'undefined') { // trigger it_boot retry if error occured while evaluating loaded script @@ -63,7 +70,7 @@ function it_catcherr(msg, url, line) if (typeof window.it_loader != 'undefined' && it_loader.sequence) stacktrace += "it_loader=" + it_loader.sequence + ";"; - it_boot_report(msg, url, line, stacktrace); + it_boot_report({msg:msg, url:url, line:line, stacktrace:stacktrace}); return !window.env || !!window.env.is_live_server; // No env or live server -> suppress error } @@ -75,20 +82,48 @@ function it_boot_addparam(url, param) return url + (url.match(/\?/) ? "&" : "?") + param; } -function it_panic(reason, msg) +function it_panic(p) { if (!document.location.href.match(/[?&]static=/)) // Avoid loop - window.setTimeout("document.location.href = it_boot_addparam(document.location.href, 'static=" + reason + "')", 500); + window.setTimeout("document.location.href = it_boot_addparam(document.location.href, 'static=" + p.reason + "')", 500); - return it_boot_report('panic ' + reason, '-', -1, (msg ? msg : '')); + p.type = "panic"; + p.stacktrace = it_stacktrace(); + return it_boot_report(p); } -function it_boot_report(msg, file, line, more) +function it_boot_report(p) { window.clearTimeout(window.it_domtimer); window.clearTimeout(window.it_panictimer); + var loader = null; + var data = ""; + var postdata = p.data; + delete p.data; + p.time = new Date().getTime() - it_starttime; + + for (var k in p) + data += (data ? '&' : '') + k + "=" + escape(p[k]).replace(/\+/g, "%2B"); - new Image().src = "/itjs/error.gif/" + escape(msg) + "|" + escape(file) + "|" + line + "|" + (new Date().getTime() - it_starttime) + "|" + escape(more); + var url = "/itjs/error.gif?" + data; + + if (postdata) + { + loader = it_boot_getloader(); + for (var k in postdata) + data += (data ? '&' : '') + k + "=" + escape(postdata[k]).replace(/\+/g, "%2B"); + } + + try + { + loader.open('POST', url); + loader.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + loader.send(data); + } + catch (e) + { + new Image().src = url; + } } function it_boot_checkcss(style, key, value) @@ -113,7 +148,7 @@ function it_boot_init() window.it_domtimer = window.setTimeout("it_boot_init()" , 42); if (style && !css) - it_panic("css"); + it_panic({reason:"css"}); return; } @@ -124,30 +159,38 @@ function it_boot_init() it_boot.sequence = ""; } -function it_boot(file, isretry) +function it_boot_getloader() { - it_boot.file = file; - it_boot.sequence = isretry ? "r" : "b"; + var result = null; try { - var loader = new XMLHttpRequest(); + result = new XMLHttpRequest(); } catch (e) { var classnames = [ 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ]; for (var i in classnames) - try { loader = new ActiveXObject(classnames[i]); break; } catch (e) {} + try { result = new ActiveXObject(classnames[i]); break; } catch (e) {} } + return result; +} + +function it_boot(file, isretry) +{ + it_boot.file = file; + it_boot.sequence = isretry ? "r" : "b"; + var loader = it_boot_getloader(); + if (loader) { it_boot.sequence += "l"; loader.open("GET", it_boot_addparam(file, "boot=1" + (isretry ? "&retry=1" : ""))); loader.onreadystatechange = function() { - var error = ""; + var error = "", code = ""; if (loader.readyState == 4) { @@ -155,10 +198,10 @@ function it_boot(file, isretry) { // check length cookie var ln = String(loader.responseText).substr(-16).match(/\*sln:\s*([0-9]+)\*/); + code = loader.responseText; if (ln && ln[1]-0 == loader.responseText.length) { it_boot.sequence += "e"; - var code = loader.responseText; if (!window.env || !!window.env.is_live_server) code = "try {" + loader.responseText + "} catch (e) { it_catcherr(e.message, it_boot.file, -1); }"; // Wrapped in try/catch as Konqueror does not support window.onerror if (window.execScript) @@ -175,7 +218,7 @@ function it_boot(file, isretry) if (error) { if (isretry) - it_panic('load', error); + it_panic({reason:'load', error:error, data:{code:code}}); else it_boot(file, true); } diff --git a/itjs/error.gif b/itjs/error.gif deleted file mode 100644 index 5bfd67a..0000000 Binary files a/itjs/error.gif and /dev/null differ -- cgit v1.2.3