changes to integration error handling:
- show the error message for errors during initialization - allow Python to throw ExceptionAlreadyDisplayed to suppress a further error message
This commit is contained in:
parent
ef28a3a705
commit
e36979747e
|
@ -305,61 +305,73 @@ Zotero.Integration = new function() {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to create a new document; otherwise display an error using the alert service
|
// Try to execute the command; otherwise display an error in alert service or word processor
|
||||||
try {
|
// (depending on what is possible)
|
||||||
var document = (application.getDocument && docId ? application.getDocument(docId) : application.getActiveDocument());
|
var integration, document;
|
||||||
var integration = new Zotero.Integration.Document(application, document);
|
|
||||||
} catch(e) {
|
|
||||||
_inProgress = false;
|
|
||||||
Zotero.Integration.activate();
|
|
||||||
Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
|
||||||
.getService(Components.interfaces.nsIPromptService)
|
|
||||||
.alert(null, Zotero.getString("integration.error.title"),
|
|
||||||
Zotero.getString("integration.error.generic"));
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to execute the command; otherwise display an error in the word processor
|
|
||||||
try {
|
try {
|
||||||
|
document = (application.getDocument && docId ? application.getDocument(docId) : application.getActiveDocument());
|
||||||
|
integration = new Zotero.Integration.Document(application, document);
|
||||||
integration[command]();
|
integration[command]();
|
||||||
integration.cleanup();
|
integration.cleanup();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
integration.cleanup();
|
if(integration) {
|
||||||
|
try {
|
||||||
|
integration.cleanup();
|
||||||
|
} catch(e) {
|
||||||
|
Components.utils.reportError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!(e instanceof Zotero.Integration.UserCancelledException)) {
|
if(!(e instanceof Zotero.Integration.UserCancelledException)) {
|
||||||
if(e instanceof Zotero.Integration.DisplayException) {
|
try {
|
||||||
integration._doc.displayAlert(e.toString(),
|
var displayError = null;
|
||||||
Components.interfaces.zoteroIntegrationDocument.DIALOG_ICON_STOP,
|
if(e instanceof Zotero.Integration.DisplayException) {
|
||||||
Components.interfaces.zoteroIntegrationDocument.DIALOG_BUTTONS_OK);
|
displayError = e.toString();
|
||||||
} else {
|
} else {
|
||||||
// check to see whether there's a pyxpcom error in the console, since it doesn't
|
// check to see whether there's a pyxpcom error in the console, since it doesn't
|
||||||
// get thrown directly
|
// get thrown directly
|
||||||
var message = "";
|
var message = "";
|
||||||
|
|
||||||
var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
|
var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
|
||||||
.getService(Components.interfaces.nsIConsoleService);
|
.getService(Components.interfaces.nsIConsoleService);
|
||||||
|
|
||||||
var messages = {};
|
var messages = {};
|
||||||
consoleService.getMessageArray(messages, {});
|
consoleService.getMessageArray(messages, {});
|
||||||
messages = messages.value;
|
messages = messages.value;
|
||||||
if(messages && messages.length) {
|
if(messages && messages.length) {
|
||||||
var lastMessage = messages[messages.length-1];
|
var lastMessage = messages[messages.length-1];
|
||||||
try {
|
try {
|
||||||
var error = lastMessage.QueryInterface(Components.interfaces.nsIScriptError);
|
var error = lastMessage.QueryInterface(Components.interfaces.nsIScriptError);
|
||||||
} catch(e2) {
|
} catch(e2) {
|
||||||
if(lastMessage.message && lastMessage.message.substr(0, 12) == "ERROR:xpcom:") {
|
if(lastMessage.message && lastMessage.message.substr(0, 12) == "ERROR:xpcom:") {
|
||||||
// print just the last line of the message, but re-throw the rest
|
// print just the last line of the message, but re-throw the rest
|
||||||
message = lastMessage.message.substr(0, lastMessage.message.length-1);
|
message = lastMessage.message.substr(0, lastMessage.message.length-1);
|
||||||
message = "\n"+message.substr(message.lastIndexOf("\n"))
|
message = "\n"+message.substr(message.lastIndexOf("\n"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!message && typeof(e) == "object" && e.message) message = "\n\n"+e.message;
|
||||||
|
|
||||||
|
if(message != "\n\nExceptionAlreadyDisplayed") {
|
||||||
|
displayError = Zotero.getString("integration.error.generic")+message;
|
||||||
|
}
|
||||||
|
Zotero.debug(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!message && typeof(e) == "object" && e.message) message = "\n\n"+e.message;
|
if(displayError) {
|
||||||
|
if(integration) {
|
||||||
integration._doc.displayAlert(Zotero.getString("integration.error.generic")+message,
|
integration._doc.displayAlert(displayError,
|
||||||
Components.interfaces.zoteroIntegrationDocument.DIALOG_ICON_STOP,
|
Components.interfaces.zoteroIntegrationDocument.DIALOG_ICON_STOP,
|
||||||
Components.interfaces.zoteroIntegrationDocument.DIALOG_BUTTONS_OK);
|
Components.interfaces.zoteroIntegrationDocument.DIALOG_BUTTONS_OK);
|
||||||
Zotero.debug(e);
|
} else {
|
||||||
|
Zotero.Integration.activate();
|
||||||
|
Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
||||||
|
.getService(Components.interfaces.nsIPromptService)
|
||||||
|
.alert(null, Zotero.getString("integration.error.title"), displayError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user