Pass exceptions directly to logger.

This commit is contained in:
wolfbeast 2018-10-24 14:13:44 +02:00 • committed by Roy Tam
commit 5075edbd77
13 changed files with 49 additions and 59 deletions

View file

@ -488,8 +488,7 @@ AddonsReconciler.prototype = {
try {
listener.changeListener.call(listener, date, change, state);
} catch (ex) {
this._log.warn("Exception calling change listener: " +
Utils.exceptionStr(ex));
this._log.warn("Exception calling change listener: ", ex);
}
}
},
@ -635,7 +634,7 @@ AddonsReconciler.prototype = {
}
}
catch (ex) {
this._log.warn("Exception: " + Utils.exceptionStr(ex));
this._log.warn("Exception: ", ex);
}
},

View file

@ -164,7 +164,7 @@ AddonUtilsInternal.prototype = {
install.install();
}
catch (ex) {
this._log.error("Error installing add-on: " + Utils.exceptionstr(ex));
this._log.error("Error installing add-on: ", ex);
cb(ex, null);
}
}.bind(this), options.requireSecureURI);

View file

@ -310,7 +310,7 @@ Store.prototype = {
throw ex.cause;
} catch (ex) {
this._log.warn("Failed to apply incoming record " + record.id);
this._log.warn("Encountered exception: " + Utils.exceptionStr(ex));
this._log.warn("Encountered exception: ", ex);
failed.push(record.id);
}
};
@ -578,7 +578,7 @@ EngineManager.prototype = {
this._engines[name] = engine;
}
} catch (ex) {
this._log.error(CommonUtils.exceptionStr(ex));
this._log.error("Engine init error: ", ex);
let mesg = ex.message ? ex.message : ex;
let name = engineObject || "";
@ -793,7 +793,7 @@ SyncEngine.prototype = {
return this._toFetch;
},
set toFetch(val) {
let cb = (error) => this._log.error(Utils.exceptionStr(error));
let cb = (error) => this._log.error("Failed to read JSON records to fetch: ", error);
// Coerce the array to a string for more efficient comparison.
if (val + "" == this._toFetch) {
return;
@ -818,7 +818,13 @@ SyncEngine.prototype = {
return this._previousFailed;
},
set previousFailed(val) {
let cb = (error) => this._log.error(Utils.exceptionStr(error));
let cb = (error) => {
if (error) {
this._log.error("Failed to set previousFailed", error);
} else {
this._log.debug("Successfully wrote previousFailed.");
}
}
// Coerce the array to a string for more efficient comparison.
if (val + "" == this._previousFailed) {
return;
@ -1001,8 +1007,7 @@ SyncEngine.prototype = {
} catch (ex) {
// Catch any error that escapes from applyIncomingBatch. At present
// those will all be abort events.
this._log.warn("Got exception " + Utils.exceptionStr(ex) +
", aborting processIncoming.");
this._log.warn("Got exception, aborting processIncoming. ", ex);
aborting = ex;
}
this._tracker.ignoreAll = false;
@ -1070,7 +1075,7 @@ SyncEngine.prototype = {
self._log.debug("Ignoring second retry suggestion.");
// Fall through to error case.
case SyncEngine.kRecoveryStrategy.error:
self._log.warn("Error decrypting record: " + Utils.exceptionStr(ex));
self._log.warn("Error decrypting record: ", ex);
failed.push(item.id);
return;
case SyncEngine.kRecoveryStrategy.ignore:
@ -1080,7 +1085,7 @@ SyncEngine.prototype = {
}
}
} catch (ex) {
self._log.warn("Error decrypting record: " + Utils.exceptionStr(ex));
self._log.warn("Error decrypting record: ", ex);
failed.push(item.id);
return;
}
@ -1094,7 +1099,7 @@ SyncEngine.prototype = {
aborting = ex.cause;
} catch (ex) {
self._log.warn("Failed to reconcile incoming record " + item.id);
self._log.warn("Encountered exception: " + Utils.exceptionStr(ex));
self._log.warn("Encountered exception: ", ex);
failed.push(item.id);
return;
}
@ -1466,7 +1471,7 @@ SyncEngine.prototype = {
up.pushData(out);
}
catch(ex) {
this._log.warn("Error creating record: " + Utils.exceptionStr(ex));
this._log.warn("Error creating record: ", ex);
}
// Partial upload
@ -1558,7 +1563,7 @@ SyncEngine.prototype = {
test.get();
}
catch(ex) {
this._log.debug("Failed test decrypt: " + Utils.exceptionStr(ex));
this._log.debug("Failed test decrypt: ", ex);
}
return canDecrypt;

View file

@ -373,8 +373,7 @@ BookmarksEngine.prototype = {
// Failure to create a backup is somewhat bad, but probably not bad
// enough to prevent syncing of bookmarks - so just log the error and
// continue.
this._log.warn("Got exception \"" + Utils.exceptionStr(ex) +
"\" backing up bookmarks, but continuing with sync.");
this._log.warn("Got exception backing up bookmarks, but continuing with sync.", ex);
cb();
}
);
@ -389,9 +388,8 @@ BookmarksEngine.prototype = {
try {
guidMap = this._buildGUIDMap();
} catch (ex) {
this._log.warn("Got exception \"" + Utils.exceptionStr(ex) +
"\" building GUID map." +
" Skipping all other incoming items.");
this._log.warn("Got exception building GUID map." +
" Skipping all other incoming items.", ex);
throw {code: Engine.prototype.eEngineAbortApplyIncoming,
cause: ex};
}
@ -637,7 +635,7 @@ BookmarksStore.prototype = {
return true;
}
} catch(ex) {
this._log.debug("Failed to reparent item. " + Utils.exceptionStr(ex));
this._log.debug("Failed to reparent item. ", ex);
}
return false;
},
@ -1265,8 +1263,7 @@ BookmarksStore.prototype = {
let u = PlacesUtils.bookmarks.getBookmarkURI(itemID);
this._tagURI(u, tags);
} catch (e) {
this._log.warn("Got exception fetching URI for " + itemID + ": not tagging. " +
Utils.exceptionStr(e));
this._log.warn("Got exception fetching URI for " + itemID + ": not tagging. ", e);
// I guess it doesn't have a URI. Don't try to tag it.
return;

View file

@ -67,7 +67,7 @@ PasswordEngine.prototype = {
Svc.Prefs.set("deletePwdFxA", true);
Svc.Prefs.reset("deletePwd"); // The old prefname we previously used.
} catch (ex) {
this._log.debug("Password deletes failed: " + Utils.exceptionStr(ex));
this._log.debug("Password deletes failed: ", ex);
}
}
},
@ -213,7 +213,7 @@ PasswordStore.prototype = {
Services.logins.addLogin(login);
} catch(ex) {
this._log.debug("Adding record " + record.id +
" resulted in exception " + Utils.exceptionStr(ex));
" resulted in exception ", ex);
}
},
@ -246,8 +246,7 @@ PasswordStore.prototype = {
Services.logins.modifyLogin(loginItem, newinfo);
} catch(ex) {
this._log.debug("Modifying record " + record.id +
" resulted in exception " + Utils.exceptionStr(ex) +
". Not modifying.");
" resulted in exception. Not modifying.", ex);
}
},

View file

@ -337,7 +337,7 @@ IdentityManager.prototype = {
try {
this._syncKeyBundle = new SyncKeyBundle(this.username, this.syncKey);
} catch (ex) {
this._log.warn("Failed to create sync key bundle", Utils.exceptionStr(ex));
this._log.warn("Failed to create sync key bundle", ex);
return null;
}
}

View file

@ -119,7 +119,7 @@ this.NotificationButton =
callback.apply(this, arguments);
} catch (e) {
let logger = Log.repository.getLogger("Sync.Notifications");
logger.error("An exception occurred: " + Utils.exceptionStr(e));
logger.error("An exception occurred: ", e);
logger.info(Utils.stackTrace(e));
throw e;
}

View file

@ -599,7 +599,7 @@ ErrorHandler.prototype = {
this.checkServerError(exception);
Status.engines = [engine_name, exception.failureCode || ENGINE_UNKNOWN_FAIL];
this._log.debug(engine_name + " failed: " + Utils.exceptionStr(exception));
this._log.debug(engine_name + " failed: ", exception);
break;
case "weave:service:login:error":
this.resetFileLog(this._logManager.REASON_ERROR);

View file

@ -236,7 +236,7 @@ RecordManager.prototype = {
return this.set(url, record);
} catch(ex) {
this._log.debug("Failed to import record: " + Utils.exceptionStr(ex));
this._log.debug("Failed to import record: ", ex);
return null;
}
},

View file

@ -231,7 +231,7 @@ AsyncResource.prototype = {
channel.asyncOpen(listener, null);
} catch (ex) {
// asyncOpen can throw in a bunch of cases -- e.g., a forbidden port.
this._log.warn("Caught an error in asyncOpen: " + CommonUtils.exceptionStr(ex));
this._log.warn("Caught an error in asyncOpen: ", ex);
CommonUtils.nextTick(callback.bind(this, ex));
}
},
@ -278,8 +278,7 @@ AsyncResource.prototype = {
} catch(ex) {
// Got a response, but an exception occurred during processing.
// This shouldn't occur.
this._log.warn("Caught unexpected exception " + CommonUtils.exceptionStr(ex) +
" in _onComplete.");
this._log.warn("Caught unexpected exception in _onComplete. ", ex);
this._log.debug(CommonUtils.stackTrace(ex));
}
@ -318,8 +317,7 @@ AsyncResource.prototype = {
contentLength + ".");
}
} catch (ex) {
this._log.debug("Caught exception " + CommonUtils.exceptionStr(ex) +
" visiting headers in _onComplete.");
this._log.debug("Caught exception visiting headers in _onComplete", ex);
this._log.debug(CommonUtils.stackTrace(ex));
}
@ -335,7 +333,7 @@ AsyncResource.prototype = {
try {
return JSON.parse(ret);
} catch (ex) {
this._log.warn("Got exception parsing response body: \"" + CommonUtils.exceptionStr(ex));
this._log.warn("Got exception parsing response body", ex);
// Stringify to avoid possibly printing non-printable characters.
this._log.debug("Parse fail: Response body starts: \"" +
JSON.stringify((ret + "").slice(0, 100)) +
@ -541,7 +539,7 @@ ChannelListener.prototype = {
siStream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
siStream.init(stream);
} catch (ex) {
this._log.warn("Exception creating nsIScriptableInputStream." + CommonUtils.exceptionStr(ex));
this._log.warn("Exception creating nsIScriptableInputStream", ex);
this._log.debug("Parameters: " + req.URI.spec + ", " + stream + ", " + off + ", " + count);
// Cannot proceed, so rethrow and allow the channel to cancel itself.
throw ex;
@ -558,8 +556,7 @@ ChannelListener.prototype = {
this._onProgress();
} catch (ex) {
this._log.warn("Got exception calling onProgress handler during fetch of "
+ req.URI.spec);
this._log.debug(CommonUtils.exceptionStr(ex));
+ req.URI.spec, ex);
this._log.trace("Rethrowing; expect a failure code from the HTTP channel.");
throw ex;
}
@ -574,7 +571,7 @@ ChannelListener.prototype = {
try {
CommonUtils.namedTimer(this.abortRequest, this._timeout, this, "abortTimer");
} catch (ex) {
this._log.warn("Got exception extending abort timer: " + CommonUtils.exceptionStr(ex));
this._log.warn("Got exception extending abort timer: ", ex);
}
},
@ -668,7 +665,7 @@ ChannelNotificationListener.prototype = {
}
}
} catch (ex) {
this._log.error("Error copying headers: " + CommonUtils.exceptionStr(ex));
this._log.error("Error copying headers: ", ex);
}
// We let all redirects proceed.

View file

@ -465,8 +465,7 @@ Sync11Service.prototype = {
this.engineManager.register(ns[engineName]);
} catch (ex) {
this._log.warn("Could not register engine " + name + ": " +
CommonUtils.exceptionStr(ex));
this._log.warn("Could not register engine " + name + ": ", ex);
}
}
@ -661,8 +660,7 @@ Sync11Service.prototype = {
} catch (ex) {
// This means no keys are present, or there's a network error.
this._log.debug("Failed to fetch and verify keys: "
+ Utils.exceptionStr(ex));
this._log.debug("Failed to fetch and verify keys: ", ex);
this.errorHandler.checkServerError(ex);
return false;
}
@ -759,7 +757,7 @@ Sync11Service.prototype = {
}
} catch (ex) {
// Must have failed on some network issue
this._log.debug("verifyLogin failed: " + Utils.exceptionStr(ex));
this._log.debug("verifyLogin failed: ", ex);
this.status.login = LOGIN_FAILED_NETWORK_ERROR;
this.errorHandler.checkServerError(ex);
return false;
@ -832,8 +830,7 @@ Sync11Service.prototype = {
try {
cb.wait();
} catch (ex) {
this._log.debug("Password change failed: " +
CommonUtils.exceptionStr(ex));
this._log.debug("Password change failed: ", ex);
return false;
}
@ -879,8 +876,7 @@ Sync11Service.prototype = {
try {
engine.removeClientData();
} catch(ex) {
this._log.warn("Deleting client data for " + engine.name + " failed:"
+ Utils.exceptionStr(ex));
this._log.warn("Deleting client data for " + engine.name + " failed:", ex);
}
}
this._log.debug("Finished deleting client data.");
@ -1508,7 +1504,7 @@ Sync11Service.prototype = {
try {
response = res.delete();
} catch (ex) {
this._log.debug("Failed to wipe server: " + CommonUtils.exceptionStr(ex));
this._log.debug("Failed to wipe server: ", ex);
throw ex;
}
if (response.status != 200 && response.status != 404) {
@ -1525,8 +1521,7 @@ Sync11Service.prototype = {
try {
response = this.resource(url).delete();
} catch (ex) {
this._log.debug("Failed to wipe '" + name + "' collection: " +
Utils.exceptionStr(ex));
this._log.debug("Failed to wipe '" + name + "' collection: ", ex);
throw ex;
}
@ -1672,8 +1667,7 @@ Sync11Service.prototype = {
return this.getStorageRequest(url).get(function onComplete(error) {
// Note: 'this' is the request.
if (error) {
this._log.debug("Failed to retrieve '" + info_type + "': " +
Utils.exceptionStr(error));
this._log.debug("Failed to retrieve '" + info_type + "': ", error);
return callback(error);
}
if (this.response.status != 200) {

View file

@ -136,8 +136,7 @@ EngineSynchronizer.prototype = {
try {
this._updateEnabledEngines();
} catch (ex) {
this._log.debug("Updating enabled engines failed: " +
Utils.exceptionStr(ex));
this._log.debug("Updating enabled engines failed: ", ex);
this.service.errorHandler.checkServerError(ex);
this.onComplete(ex);
return;

View file

@ -77,7 +77,7 @@ this.Utils = {
return func.call(thisArg);
}
catch(ex) {
thisArg._log.debug("Exception: " + Utils.exceptionStr(ex));
thisArg._log.debug("Exception: ", ex);
if (exceptionCallback) {
return exceptionCallback.call(thisArg, ex);
}