refactor error reporting to AppBase; keep exception_error() for now as a shim

This commit is contained in:
Andrew Dolgov 2018-12-03 13:38:13 +03:00
parent a049b5bd88
commit 71fc6d45bd
17 changed files with 222 additions and 267 deletions

View File

@ -42,10 +42,8 @@ require(['dojo/parser', "dojo/ready", 'dijit/form/Button','dijit/form/CheckBox',
});
function fetchProfiles() {
try {
var query = "op=getProfiles&login=" + encodeURIComponent(document.forms["loginForm"].login.value);
const query = "op=getProfiles&login=" + encodeURIComponent(document.forms["loginForm"].login.value);
if (query) {
new Ajax.Request("public.php", {
parameters: query,
onComplete: function(transport) {
@ -56,27 +54,14 @@ function fetchProfiles() {
} });
}
} catch (e) {
exception_error("fetchProfiles", e);
}
}
function gotoRegForm() {
window.location.href = "register.php";
return false;
}
function bwLimitChange(elem) {
try {
var limit_set = elem.checked;
setCookie("ttrss_bwlimit", limit_set,
Cookie.set("ttrss_bwlimit", elem.checked,
<?php print SESSION_COOKIE_LIFETIME ?>);
} catch (e) {
exception_error("bwLimitChange", e);
}
}
</script>

View File

@ -7,15 +7,15 @@ define(["dojo/_base/declare"], function (declare) {
hotkey_prefix: 0,
hotkey_prefix_pressed: false,
hotkey_prefix_timeout: 0,
constructor: function() {
window.onerror = this.Error.onWindowError;
},
getInitParam: function(k) {
return this._initParams[k];
},
setInitParam: function(k, v) {
this._initParams[k] = v;
},
constructor: function(args) {
//
},
enableCsrfSupport: function() {
Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
function (callOriginal, options) {
@ -176,7 +176,7 @@ define(["dojo/_base/declare"], function (declare) {
if (callback) callback(transport);
} catch (e) {
exception_error(e);
this.Error.report(e);
}
});
@ -355,5 +355,67 @@ define(["dojo/_base/declare"], function (declare) {
explainError: function(code) {
return this.displayDlg(__("Error explained"), "explainError", code);
},
Error: {
report: function(error, params) {
params = params || {};
if (!error) return;
console.error("[Error.report]", error, params);
const message = params.message ? params.message : error.toString();
try {
xhrPost("backend.php",
{op: "rpc", method: "log",
file: params.filename ? params.filename : error.fileName,
line: params.lineno ? params.lineno : error.lineNumber,
msg: message,
context: error.stack},
(transport) => {
console.warn("[Error.report] log response", transport.responseText);
});
} catch (re) {
console.error("[Error.report] exception while saving logging error on server", re);
}
try {
if (dijit.byId("exceptionDlg"))
dijit.byId("exceptionDlg").destroyRecursive();
let content = "<div class='fatalError'><p>" + message + "</p>";
if (error.stack)
content += "<div><b>Stack trace:</b></div>" +
"<textarea name=\"stack\" readonly=\"1\">" + error.stack + "</textarea>";
content += "<div style='text-align : center'>";
content += "<button dojoType=\"dijit.form.Button\" " +
"onclick=\"dijit.byId('exceptionDlg').hide()\">" +
__('Close this window') + "</button>";
content += "</div>";
const dialog = new dijit.Dialog({
id: "exceptionDlg",
title: "Unhandled exception",
style: "width: 600px",
content: content
});
dialog.show();
} catch (de) {
console.error("[Error.report] exception while showing error dialog", de);
alert(error.stack ? error.stack : message);
}
},
onWindowError: function (message, filename, lineno, colno, error) {
// called without context (this) from window.onerror
App.Error.report(error,
{message: message, filename: filename, lineno: lineno, colno: colno});
},
}
});
});

View File

@ -168,7 +168,7 @@ define(["dojo/_base/declare"], function (declare) {
Notify.close();
} catch (e) {
exception_error(e);
App.Error.report(e);
}
})
}
@ -206,7 +206,7 @@ define(["dojo/_base/declare"], function (declare) {
if (tooltip) tooltip.attr('label', data.content_full);
}
} catch (e) {
exception_error(e);
App.Error.report(e);
}
});
}

View File

@ -152,7 +152,7 @@ define(["dojo/_base/declare"], function (declare) {
} catch (e) {
console.error(transport.responseText);
exception_error(e);
App.Error.report(e);
}
});
}

View File

@ -67,7 +67,7 @@ define(["dojo/_base/declare"], function (declare) {
parentNode.appendChild(li);
}
} catch (e) {
exception_error(e);
App.Error.report(e);
}
});
},
@ -117,7 +117,7 @@ define(["dojo/_base/declare"], function (declare) {
}
} catch (e) {
exception_error(e);
App.Error.report(e);
}
});
},
@ -238,7 +238,7 @@ define(["dojo/_base/declare"], function (declare) {
console.log("getTestResults: dialog closed, bailing out.");
}
} catch (e) {
exception_error(e);
App.Error.report(e);
}
});

View File

@ -207,7 +207,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
}
}
} catch (e) {
exception_error(e);
App.Error.report(e);
}
},
findNodeParentsAndExpandThem: function(feed, is_cat, root, parents) {
@ -242,7 +242,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
this.expandParentNodes(feed, is_cat, parents.slice(0));
}
} catch (e) {
exception_error(e);
App.Error.report(e);
}
},
selectFeed: function(feed, is_cat) {

View File

@ -198,13 +198,13 @@ define(["dojo/_base/declare"], function (declare) {
Feeds.init();
App.setLoadingProgress(25);
} catch (e) {
exception_error(e);
App.Error.report(e);
}
});
tree.startup();
} catch (e) {
exception_error(e);
App.Error.report(e);
}
},
init: function() {
@ -380,7 +380,7 @@ define(["dojo/_base/declare"], function (declare) {
Headlines.onLoaded(transport, offset);
PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]);
} catch (e) {
exception_error(e);
App.Error.report(e);
}
});
});

View File

@ -4,6 +4,16 @@
let _label_base_index = -1024;
let loading_progress = 0;
/* error reporting shim */
// TODO: deprecated; remove
function exception_error(e, e_compat, filename, lineno, colno) {
if (typeof e == "string")
e = e_compat;
App.Error.report(e, {filename: filename, lineno: lineno, colno: colno});
}
/* xhr shorthand helpers */
function xhrPost(url, params, complete) {
@ -118,71 +128,6 @@ const Cookie = {
}
};
/* error reporting */
function report_error(message, filename, lineno, colno, error) {
exception_error(error, null, filename, lineno);
}
function exception_error(e, e_compat, filename, lineno, colno) {
if (typeof e == "string") e = e_compat;
if (!e) return; // no exception object, nothing to report.
try {
console.error(e);
const msg = e.toString();
try {
xhrPost("backend.php",
{op: "rpc", method: "log",
file: e.fileName ? e.fileName : filename,
line: e.lineNumber ? e.lineNumber : lineno,
msg: msg, context: e.stack},
(transport) => {
console.warn(transport.responseText);
});
} catch (e) {
console.error("Exception while trying to log the error.", e);
}
let content = "<div class='fatalError'><p>" + msg + "</p>";
if (e.stack) {
content += "<div><b>Stack trace:</b></div>" +
"<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>";
}
content += "</div>";
content += "<div class='dlgButtons'>";
content += "<button dojoType=\"dijit.form.Button\" "+
"onclick=\"dijit.byId('exceptionDlg').hide()\">" +
__('Close') + "</button>";
content += "</div>";
if (dijit.byId("exceptionDlg"))
dijit.byId("exceptionDlg").destroyRecursive();
const dialog = new dijit.Dialog({
id: "exceptionDlg",
title: "Unhandled exception",
style: "width: 600px",
content: content});
dialog.show();
} catch (ei) {
console.error("Exception while trying to report an exception:", ei);
console.error("Original exception:", e);
alert("Exception occured while trying to report an exception.\n" +
ei.stack + "\n\nOriginal exception:\n" + e.stack);
}
}
/* runtime notifications */
const Notify = {

View File

@ -58,10 +58,6 @@ require(["dojo/_base/kernel",
try {
const _App = declare("fox.App", AppBase, {
constructor: function() {
window.onerror = function (message, filename, lineno, colno, error) {
report_error(message, filename, lineno, colno, error);
};
parser.parse();
this.setLoadingProgress(50);
@ -73,7 +69,7 @@ require(["dojo/_base/kernel",
try {
this.backendSanityCallback(transport);
} catch (e) {
exception_error(e);
this.Error.report(e);
}
});
},
@ -149,7 +145,7 @@ require(["dojo/_base/kernel",
App = new _App();
} catch (e) {
exception_error(e);
this.Error.report(e);
}
});
});

View File

@ -65,10 +65,6 @@ require(["dojo/_base/kernel",
_widescreen_mode: false,
hotkey_actions: {},
constructor: function () {
window.onerror = function (message, filename, lineno, colno, error) {
report_error(message, filename, lineno, colno, error);
};
parser.parse();
this.setLoadingProgress(30);
@ -91,7 +87,7 @@ require(["dojo/_base/kernel",
try {
App.backendSanityCallback(transport);
} catch (e) {
exception_error(e);
App.Error.report(e);
}
});
},
@ -555,7 +551,7 @@ require(["dojo/_base/kernel",
App = new _App();
} catch (e) {
exception_error(e);
App.Error.report(e);
}
});
});

View File

@ -1,5 +1,4 @@
function embedOriginalArticle(id) {
try {
const hasSandbox = "sandbox" in document.createElement("iframe");
if (!hasSandbox) {
@ -54,7 +53,4 @@ function embedOriginalArticle(id) {
}
});
} catch (e) {
exception_error("embedOriginalArticle", e);
}
}

View File

@ -50,7 +50,7 @@ function exportData() {
"Error occured, could not export data.";
}
} catch (e) {
exception_error("exportData", e, transport.responseText);
App.Error.report(e);
}
Notify.close();
@ -71,7 +71,7 @@ function exportData() {
} catch (e) {
exception_error("exportData", e);
App.Error.report(e);
}
}
@ -100,7 +100,7 @@ function dataImportComplete(iframe) {
dialog.show();
} catch (e) {
exception_error("dataImportComplete", e);
App.Error.report(e);
}
}

View File

@ -1,7 +1,6 @@
function emailArticle(id) {
try {
if (!id) {
var ids = Headlines.getSelected();
let ids = Headlines.getSelected();
if (ids.length == 0) {
alert(__("No articles selected."));
@ -14,9 +13,9 @@ function emailArticle(id) {
if (dijit.byId("emailArticleDlg"))
dijit.byId("emailArticleDlg").destroyRecursive();
var query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle&param=" + encodeURIComponent(id);
const query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle&param=" + encodeURIComponent(id);
dialog = new dijit.Dialog({
const dialog = new dijit.Dialog({
id: "emailArticleDlg",
title: __("Forward article by email"),
style: "width: 600px",
@ -48,10 +47,6 @@ function emailArticle(id) {
}); */
dialog.show();
} catch (e) {
exception_error("emailArticle", e);
}
}

View File

@ -1,5 +1,4 @@
function mailtoArticle(id) {
try {
if (!id) {
const ids = Headlines.getSelected();
@ -16,17 +15,13 @@ function mailtoArticle(id) {
const query = "backend.php?op=pluginhandler&plugin=mailto&method=emailArticle&param=" + encodeURIComponent(id);
dialog = new dijit.Dialog({
const dialog = new dijit.Dialog({
id: "emailArticleDlg",
title: __("Forward article by email"),
style: "width: 600px",
href: query});
dialog.show();
} catch (e) {
exception_error("emailArticle", e);
}
}

View File

@ -1,12 +1,7 @@
function nsfwShow(elem) {
try {
content = elem.parentNode.getElementsBySelector("div.nswf.content")[0];
let content = elem.parentNode.getElementsBySelector("div.nswf.content")[0];
if (content) {
Element.toggle(content);
}
} catch (e) {
exception_error("nswfSHow", e);
}
}

View File

@ -1,29 +1,20 @@
var _shorten_expanded_threshold = 1.5; //window heights
function expandSizeWrapper(id) {
try {
const row = $(id);
console.log(row);
if (row) {
const content = row.select(".contentSizeWrapper")[0];
const link = row.select(".expandPrompt")[0];
if (content) content.removeClassName("contentSizeWrapper");
if (link) Element.hide(link);
}
} catch (e) {
exception_error("expandSizeWrapper", e);
}
return false;
}
require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
ready(function() {
PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) {
window.setTimeout(function() {
@ -48,5 +39,4 @@ require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
return true;
});
});
});

View File

@ -135,13 +135,13 @@
f.sub_btn.disabled = true;
}
} catch (e) {
exception_error("checkUsername_callback", e);
App.Error.report(e);
}
} });
} catch (e) {
exception_error("checkUsername", e);
App.Error.report(e);
}
return false;
@ -171,7 +171,7 @@
return true;
} catch (e) {
exception_error("validateRegForm", e);
alert(e.stack);
return false;
}
}