From 5bb324e2ebe42ea026568cebb27b668a4dc0df1a Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Mon, 19 Mar 2007 19:21:32 +0000 Subject: [PATCH] - fix issues with errors in async detectCode --- chrome/content/zotero/xpcom/ingester.js | 2 +- chrome/content/zotero/xpcom/translate.js | 20 ++++++++++++++------ chrome/content/zotero/xpcom/utilities.js | 6 +++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/chrome/content/zotero/xpcom/ingester.js b/chrome/content/zotero/xpcom/ingester.js index fd92473c4..b62d04d9e 100644 --- a/chrome/content/zotero/xpcom/ingester.js +++ b/chrome/content/zotero/xpcom/ingester.js @@ -583,7 +583,7 @@ Zotero.OpenURL = new function() { if(pAu.lastName == au.lastName && (pAu.firstName == au.firstName == "" || (pAu.firstName.length >= au.firstName.length && - pAu.substr(0, au.firstName.length) == au.firstName))) { + pAu.firstName.substr(0, au.firstName.length) == au.firstName))) { pushMe = false; break; } diff --git a/chrome/content/zotero/xpcom/translate.js b/chrome/content/zotero/xpcom/translate.js index 80a59c479..8a2c7e171 100644 --- a/chrome/content/zotero/xpcom/translate.js +++ b/chrome/content/zotero/xpcom/translate.js @@ -495,7 +495,8 @@ Zotero.Translate.prototype.getTranslators = function() { // see which translators can translate this._translatorSearch = new Zotero.Translate.TranslatorSearch(this, translators); - Zotero.debug(this._translatorSearch.foundTranslators); + // erroring should call complete + this.error = function(value, error) { this._translatorSearch.complete(value, error) }; // return translators if asynchronous if(!this._translatorSearch.asyncMode) return this._translatorSearch.foundTranslators; @@ -557,6 +558,9 @@ Zotero.Translate.prototype.translate = function() { throw("cannot translate: no location specified"); } + // erroring should end + this.error = this._translationComplete; + if(!this._loadTranslator()) { return; } @@ -885,7 +889,7 @@ Zotero.Translate.prototype._translationComplete = function(returnValue, error) { if(!returnValue) { var errorString = this._generateErrorString(error); - this._debug("Translation using "+this.translator[0].label+" failed: \n"+errorString); + this._debug("Translation using "+(this.translator && this.translator[0] && this.translator[0].label ? this.translator[0].label : "no translator")+" failed: \n"+errorString); if(this.type == "web") { // report translation error for webpages @@ -2076,8 +2080,7 @@ Zotero.Translate.TranslatorSearch.prototype.execute = function() { returnValue = this.translate._sandbox.detectImport(); } } catch(e) { - Zotero.debug(e+' in executing detectCode for '+translator.label); - this.execute(); + this.complete(returnValue, e); return; } @@ -2131,12 +2134,17 @@ Zotero.Translate.TranslatorSearch.prototype.processReturnValue = function(transl this.foundTranslators.push(translator); } -Zotero.Translate.TranslatorSearch.prototype.complete = function(returnValue) { +Zotero.Translate.TranslatorSearch.prototype.complete = function(returnValue, error) { // reset done function this.translate._sandbox.Zotero.done = undefined; this.translate.waitForCompletion = false; - this.processReturnValue(this.currentTranslator, returnValue); + if(returnValue) { + this.processReturnValue(this.currentTranslator, returnValue); + } else if(error) { + var errorString = this.translate._generateErrorString(error); + Zotero.debug("detectCode for "+(this.currentTranslator ? this.currentTranslator.label : "no translator")+" failed: \n"+errorString); + } this.currentTranslator = undefined; this.asyncMode = false; diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index fcefa7d9b..83a983cb7 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -441,7 +441,7 @@ Zotero.Utilities.Ingester.prototype.processDocuments = function(urls, processor, if(!exception) { var translate = this.translate; exception = function(e) { - translate._translationComplete(false, e); + translate.error(false, e); } } @@ -485,7 +485,7 @@ Zotero.Utilities.Ingester.HTTP.prototype.doGet = function(urls, processor, done) } } } catch(e) { - me.translate._translationComplete(false, e); + me.translate.error(false, e); } }); } @@ -503,7 +503,7 @@ Zotero.Utilities.Ingester.HTTP.prototype.doPost = function(url, body, onDone, co try { onDone(xmlhttp.responseText, xmlhttp); } catch(e) { - translate._translationComplete(false, e); + translate.error(false, e); } }, contentType); }