1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-13 13:45:56 +00:00

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

@@ -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);
}
});
});