Skip to content

Commit

Permalink
Adds SSE-based error and debug report sharing with the client
Browse files Browse the repository at this point in the history
  • Loading branch information
adomasven committed Oct 26, 2017
1 parent 1091d04 commit 000978c
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 163 deletions.
2 changes: 1 addition & 1 deletion gulpfile.js
Expand Up @@ -109,14 +109,14 @@ var backgroundInclude = [
'cachedTypes.js',
'zotero/date.js',
'zotero/debug.js',
'errors_webkit.js',
"zotero/xregexp/xregexp.js",
"zotero/xregexp/addons/build.js",
"zotero/xregexp/addons/matchrecursive.js",
"zotero/xregexp/addons/unicode/unicode-base.js",
"zotero/xregexp/addons/unicode/unicode-categories.js",
"zotero/xregexp/addons/unicode/unicode-zotero.js",
'zotero/openurl.js',
'reports.js',
'repo.js',
'zotero/translation/tlds.js',
'zotero/translation/translator.js',
Expand Down
62 changes: 19 additions & 43 deletions src/common/connector.js
Expand Up @@ -44,6 +44,25 @@ Zotero.Connector = {
Object.assign(this.selected, data);
Zotero.Connector_Browser._updateExtensionUI();
}.bind(this)});
this.addEventListener('reports', {notify: async function(data) {
if ('errors' in data && 'get' in data.errors) {
let sysInfo = await Zotero.getSystemInfo();
let errors = await Zotero.Errors.getErrors();
Zotero.Connector.callMethod('reports', {report: `${sysInfo}\n\n${errors.join('\n\n')}`});
}
else if ('debug' in data) {
if ('get' in data.debug) {
let debug = await Zotero.Debug.get();
Zotero.Connector.callMethod('reports', {report: debug});
}
else if ('store' in data.debug) {
Zotero.Debug.setStore(data.debug.store)
}
else if ('clear' in data.debug) {
Zotero.Debug.clear();
}
}
}});

Zotero.Connector.SSE.init();
},
Expand Down Expand Up @@ -311,46 +330,3 @@ Zotero.Connector.SSE = {
};
Zotero.Connector.addEventListener = Zotero.Connector.SSE._addEventListener.bind(Zotero.Connector.SSE);
Zotero.Connector.removeEventListener = Zotero.Connector.SSE._removeEventListener.bind(Zotero.Connector.SSE);


// TODO: this does not belong here in the slightest
Zotero.Connector_Debug = new function() {
/**
* Call a callback depending upon whether debug output is being stored
*/
this.storing = function() {
return Zotero.Debug.storing;
}

/**
* Call a callback with the lines themselves
*/
this.get = function() {
return Zotero.Debug.get();
};

/**
* Call a callback with the number of lines of output
*/
this.count = function() {
return Zotero.Debug.count();
}

/**
* Submit data to the server
*/
this.submitReport = function() {
return Zotero.Debug.get().then(function(body){
return Zotero.HTTP.request("POST", ZOTERO_CONFIG.REPOSITORY_URL + "report?debug=1", {body});
}).then(function(xmlhttp) {
if (!xmlhttp.responseXML) {
throw new Error('Invalid response from server');
}
var reported = xmlhttp.responseXML.getElementsByTagName('reported');
if (reported.length != 1) {
throw new Error('The server returned an error. Please try again.');
}
return reported[0].getAttribute('reportID');
});
};
}
84 changes: 0 additions & 84 deletions src/common/errors_webkit.js

This file was deleted.

14 changes: 6 additions & 8 deletions src/common/messages.js
Expand Up @@ -115,7 +115,11 @@ var MESSAGES = {
minArgs: 4
}
},
setStore: false
setStore: false,
isStoring: true,
get: true,
count: true,
submitToZotero: true
},
Connector: {
checkIsOnline: true,
Expand All @@ -133,16 +137,10 @@ var MESSAGES = {
openConfigEditor: false,
openPreferences: false
},
Connector_Debug: {
storing: true,
get: true,
count: true,
submitReport: true
},
Errors: {
log: false,
getErrors: true,
sendErrorReport: true
submitToZotero: true
},
Messaging: {
sendMessage: true
Expand Down
16 changes: 8 additions & 8 deletions src/common/preferences/preferences.jsx
Expand Up @@ -113,7 +113,7 @@ var Zotero_Preferences = {
document.getElementById('advanced-textarea-errors').textContent = errors.join("\n\n");
}
// get debug logging info
return Zotero.Connector_Debug.count();
return Zotero.Debug.count();
}).then(function(count) {
document.getElementById('advanced-span-lines-logged').textContent = count.toString();
toggleDisabled(document.getElementById('advanced-button-view-output'), !count);
Expand Down Expand Up @@ -208,7 +208,7 @@ Zotero_Preferences.Advanced = {
init: function() {

document.getElementById("advanced-checkbox-enable-logging").onchange =
function() { Zotero.Debug.setStore(this.checked); };
function() { Zotero.Debug.setStore(this.checked, true); };
document.getElementById("advanced-checkbox-enable-at-startup").onchange =
function() { Zotero.Prefs.set('debug.store', this.checked); };
document.getElementById("advanced-checkbox-show-in-console").onchange = function() {
Expand Down Expand Up @@ -245,7 +245,7 @@ Zotero_Preferences.Advanced = {
};

// get preference values
Zotero.Connector_Debug.storing(function(status) {
Zotero.Debug.isStoring().then(function(status) {
document.getElementById('advanced-checkbox-enable-logging').checked = !!status;
});
Zotero.Prefs.getAsync("debug.store").then(function(status) {
Expand All @@ -263,7 +263,7 @@ Zotero_Preferences.Advanced = {
* Opens a new window to view debug output.
*/
viewDebugOutput: function() {
Zotero.Connector_Debug.get(function(log) {
Zotero.Debug.get().then(function(log) {
var textarea = document.getElementById("advanced-textarea-debug");
textarea.textContent = log;
textarea.style.display = "";
Expand All @@ -274,7 +274,7 @@ Zotero_Preferences.Advanced = {
* Clears stored debug output.
*/
clearDebugOutput: function() {
Zotero.Debug.clear();
Zotero.Debug.clear(true);
Zotero_Preferences.refreshData();
var textarea = document.getElementById("advanced-textarea-debug");
textarea.style.display = 'none';
Expand All @@ -287,9 +287,9 @@ Zotero_Preferences.Advanced = {
var submitOutputButton = document.getElementById('advanced-button-submit-output');
toggleDisabled(submitOutputButton, true);

return Zotero.Connector_Debug.submitReport().then(function(reportID) {
return Zotero.Debug.submitToZotero().then(function(reportID) {
alert("Your debug output has been submitted.\n\n"
+ `The Debug ID is D${reportID}.`);
+ `The Debug ID is ${reportID}.`);
}, function(e) {
alert(`An error occurred submitting your debug output.\n\n${e.message}\n\n`+
'Please check your internet connection. If the problem persists, '+
Expand All @@ -304,7 +304,7 @@ Zotero_Preferences.Advanced = {
var reportErrorsButton = document.getElementById('advanced-button-report-errors');
toggleDisabled(reportErrorsButton, true);

return Zotero.Errors.sendErrorReport().then(function(reportID) {
return Zotero.Errors.submitToZotero().then(function(reportID) {
alert(`Your error report has been submitted.\n\nReport ID: ${reportID}\n\n`+
'Please post a message to the Zotero Forums (forums.zotero.org) with this Report '+
'ID, a description of the problem, and any steps necessary to reproduce it.\n\n'+
Expand Down

0 comments on commit 000978c

Please sign in to comment.