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

View file

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

View file

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

View file

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

View file

@ -67,7 +67,7 @@ PasswordEngine.prototype = {
Svc.Prefs.set("deletePwdFxA", true); Svc.Prefs.set("deletePwdFxA", true);
Svc.Prefs.reset("deletePwd"); // The old prefname we previously used. Svc.Prefs.reset("deletePwd"); // The old prefname we previously used.
} catch (ex) { } 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); Services.logins.addLogin(login);
} catch(ex) { } catch(ex) {
this._log.debug("Adding record " + record.id + 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); Services.logins.modifyLogin(loginItem, newinfo);
} catch(ex) { } catch(ex) {
this._log.debug("Modifying record " + record.id + this._log.debug("Modifying record " + record.id +
" resulted in exception " + Utils.exceptionStr(ex) + " resulted in exception. Not modifying.", ex);
". Not modifying.");
} }
}, },

View file

@ -337,7 +337,7 @@ IdentityManager.prototype = {
try { try {
this._syncKeyBundle = new SyncKeyBundle(this.username, this.syncKey); this._syncKeyBundle = new SyncKeyBundle(this.username, this.syncKey);
} catch (ex) { } 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; return null;
} }
} }

View file

@ -119,7 +119,7 @@ this.NotificationButton =
callback.apply(this, arguments); callback.apply(this, arguments);
} catch (e) { } catch (e) {
let logger = Log.repository.getLogger("Sync.Notifications"); 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)); logger.info(Utils.stackTrace(e));
throw e; throw e;
} }

View file

@ -599,7 +599,7 @@ ErrorHandler.prototype = {
this.checkServerError(exception); this.checkServerError(exception);
Status.engines = [engine_name, exception.failureCode || ENGINE_UNKNOWN_FAIL]; 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; break;
case "weave:service:login:error": case "weave:service:login:error":
this.resetFileLog(this._logManager.REASON_ERROR); this.resetFileLog(this._logManager.REASON_ERROR);

View file

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

View file

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

View file

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

View file

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

View file

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