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

View file

@ -52,11 +52,17 @@ onmessage = function(event) {
close(fd); close(fd);
// extract message // 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 agent = parts[1].toString();
var cmd = parts[2].toString(); var cmd = parts[2].toString();
var document = parts[3] ? parts[3] : null; var document = parts[3] ? parts[3] : null;
if(agent == "Zotero" && cmd == "shutdown") { if(agent == "Zotero" && cmd == "shutdown") {
postMessage(["Debug", "Integration Worker: Shutting down"]);
lib.close(); lib.close();
return; return;
} }