commit 493b3225f6b9455131eb89ea58c7c15284bb76d9
parent 03f8f111569d893e93a1b38debc9942c5afd1e92
Author: Simon Kornblith <simon@simonster.com>
Date: Tue, 21 Dec 2010 05:49:53 +0000
improve error handling in integration worker
Diffstat:
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js
@@ -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});
diff --git a/chrome/content/zotero/xpcom/integration_worker.js b/chrome/content/zotero/xpcom/integration_worker.js
@@ -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;
}