improve error handling in integration worker

This commit is contained in:
Simon Kornblith 2010-12-21 05:49:53 +00:00
parent 03f8f11156
commit 493b3225f6
2 changed files with 15 additions and 4 deletions

View file

@ -119,11 +119,10 @@ Zotero.Integration = new function() {
}
if(pipeInitialized) {
var me = this;
// if initialization succeeded, add an observer so that we don't hang shutdown
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver({ observe: me.destroy }, "quit-application", false);
observerService.addObserver({ observe: Zotero.Integration.destroy }, "quit-application", false);
}
}
@ -210,7 +209,13 @@ Zotero.Integration = new function() {
.createInstance(Components.interfaces.nsIWorkerFactory)
.newChromeWorker("chrome://zotero/content/xpcom/integration_worker.js");
worker.onmessage = function(event) {
Zotero.Integration.execCommand(event.data[0], event.data[1], event.data[2]);
if(event.data[0] == "Exception") {
throw event.data[1];
} else if(event.data[0] == "Debug") {
Zotero.debug(event.data[1]);
} else {
Zotero.Integration.execCommand(event.data[0], event.data[1], event.data[2]);
}
}
worker.postMessage({"path":_fifoFile.path, "libc":libc});

View file

@ -52,11 +52,17 @@ onmessage = function(event) {
close(fd);
// extract message
var parts = buf.readString().match(/^([^ \n]*) ([^ \n]*)(?: ([^\n]*))?\n?$/);
string = buf.readString();
var parts = string.match(/^([^ \n]*) ([^ \n]*)(?: ([^\n]*))?\n?$/);
if(!parts) {
postMessage(["Exception", "Integration Worker: Invalid input received: "+string]);
continue;
}
var agent = parts[1].toString();
var cmd = parts[2].toString();
var document = parts[3] ? parts[3] : null;
if(agent == "Zotero" && cmd == "shutdown") {
postMessage(["Debug", "Integration Worker: Shutting down"]);
lib.close();
return;
}