Bug 1899195 - Improve logging of exceptions in mailnews/. r=mkmelin

Differential Revision: https://phabricator.services.mozilla.com/D211794

--HG--
extra : amend_source : 1d1d7e94c7b79c9d73c8c21764d0445d65de4add
This commit is contained in:
Mark Banner 2024-10-05 09:04:35 +00:00
Родитель 11d36fbb52
Коммит 93d40ac0bd
13 изменённых файлов: 120 добавлений и 132 удалений

Просмотреть файл

@ -316,117 +316,109 @@ function hasCharacters(number) {
}
function onAccept(event) {
try {
const description = document.getElementById("description").value.trim();
let hostname = cleanUpHostName(document.getElementById("hostname").value);
let port = document.getElementById("port").value;
const secure = document.getElementById("secure");
const results = document.getElementById("results").value;
let errorValue = null;
let errorArg = null;
let saslMechanism = "";
const description = document.getElementById("description").value.trim();
let hostname = cleanUpHostName(document.getElementById("hostname").value);
let port = document.getElementById("port").value;
const secure = document.getElementById("secure");
const results = document.getElementById("results").value;
let errorValue = null;
let errorArg = null;
let saslMechanism = "";
const findDupeName = function (newName) {
// Do not allow an already existing name.
for (const ab of MailServices.ab.directories) {
if (
ab.dirName.toLowerCase() == newName.toLowerCase() &&
(!gCurrentDirectory || ab.URI != gCurrentDirectory.URI)
) {
return ab.dirName;
}
const findDupeName = function (newName) {
// Do not allow an already existing name.
for (const ab of MailServices.ab.directories) {
if (
ab.dirName.toLowerCase() == newName.toLowerCase() &&
(!gCurrentDirectory || ab.URI != gCurrentDirectory.URI)
) {
return ab.dirName;
}
return null;
};
}
return null;
};
if (!description) {
errorValue = "invalidName";
} else if ((errorArg = findDupeName(description))) {
errorValue = "duplicateNameText";
} else if (!isLegalHostNameOrIP(hostname)) {
errorValue = "invalidHostname";
} else if (port && hasCharacters(port)) {
// XXX write isValidDn and call it on the dn string here?
errorValue = "invalidPortNumber";
} else if (results && hasCharacters(results)) {
errorValue = "invalidResults";
if (!description) {
errorValue = "invalidName";
} else if ((errorArg = findDupeName(description))) {
errorValue = "duplicateNameText";
} else if (!isLegalHostNameOrIP(hostname)) {
errorValue = "invalidHostname";
} else if (port && hasCharacters(port)) {
// XXX write isValidDn and call it on the dn string here?
errorValue = "invalidPortNumber";
} else if (results && hasCharacters(results)) {
errorValue = "invalidResults";
}
if (!errorValue) {
if (!port) {
port = secure.checked ? kDefaultSecureLDAPPort : kDefaultLDAPPort;
}
if (hostname.includes(":")) {
// Wrap IPv6 address in [].
hostname = `[${hostname}]`;
}
const ldapUrl = Services.io
.newURI(`${secure.checked ? "ldaps" : "ldap"}://${hostname}:${port}`)
.QueryInterface(Ci.nsILDAPURL);
ldapUrl.dn = document.getElementById("basedn").value;
ldapUrl.scope = document.getElementById("one").selected
? Ci.nsILDAPURL.SCOPE_ONELEVEL
: Ci.nsILDAPURL.SCOPE_SUBTREE;
ldapUrl.filter = document.getElementById("search").value;
if (document.getElementById("GSSAPI").selected) {
saslMechanism = "GSSAPI";
}
if (!errorValue) {
if (!port) {
port = secure.checked ? kDefaultSecureLDAPPort : kDefaultLDAPPort;
}
if (hostname.includes(":")) {
// Wrap IPv6 address in [].
hostname = `[${hostname}]`;
}
const ldapUrl = Services.io
.newURI(`${secure.checked ? "ldaps" : "ldap"}://${hostname}:${port}`)
.QueryInterface(Ci.nsILDAPURL);
ldapUrl.dn = document.getElementById("basedn").value;
ldapUrl.scope = document.getElementById("one").selected
? Ci.nsILDAPURL.SCOPE_ONELEVEL
: Ci.nsILDAPURL.SCOPE_SUBTREE;
ldapUrl.filter = document.getElementById("search").value;
if (document.getElementById("GSSAPI").selected) {
saslMechanism = "GSSAPI";
}
// check if we are modifying an existing directory or adding a new directory
if (gCurrentDirectory) {
gCurrentDirectory.dirName = description;
gCurrentDirectory.lDAPURL = ldapUrl;
window.opener.gNewServerString = gCurrentDirectory.dirPrefId;
} else {
// adding a new directory
window.opener.gNewServerString = MailServices.ab.newAddressBook(
description,
ldapUrl.spec,
Ci.nsIAbManager.LDAP_DIRECTORY_TYPE
);
}
// XXX This is really annoying - both new/modify Address Book don't
// give us back the new directory we just created - so go find it from
// rdf so we can set a few final things up on it.
var targetURI = "moz-abldapdirectory://" + window.opener.gNewServerString;
var theDirectory = MailServices.ab
.getDirectory(targetURI)
.QueryInterface(Ci.nsIAbLDAPDirectory);
theDirectory.maxHits = results;
theDirectory.authDn = document.getElementById("login").value;
theDirectory.saslMechanism = saslMechanism;
window.opener.gNewServer = description;
// set window.opener.gUpdate to true so that LDAP Directory Servers
// dialog gets updated
window.opener.gUpdate = true;
window.arguments[0].newDirectoryUID = theDirectory.UID;
if ("onNewDirectory" in window.arguments[0]) {
window.arguments[0].onNewDirectory(theDirectory);
}
// check if we are modifying an existing directory or adding a new directory
if (gCurrentDirectory) {
gCurrentDirectory.dirName = description;
gCurrentDirectory.lDAPURL = ldapUrl;
window.opener.gNewServerString = gCurrentDirectory.dirPrefId;
} else {
const addressBookBundle = document.getElementById("bundle_addressBook");
let errorText;
if (errorArg) {
errorText = addressBookBundle.getFormattedString(errorValue, [
errorArg,
]);
} else {
errorText = addressBookBundle.getString(errorValue);
}
Services.prompt.alert(window, document.title, errorText);
event.preventDefault();
// adding a new directory
window.opener.gNewServerString = MailServices.ab.newAddressBook(
description,
ldapUrl.spec,
Ci.nsIAbManager.LDAP_DIRECTORY_TYPE
);
}
} catch (outer) {
console.error(
"Internal error in pref-directory-add.js:onAccept() " + outer
);
// XXX This is really annoying - both new/modify Address Book don't
// give us back the new directory we just created - so go find it from
// rdf so we can set a few final things up on it.
var targetURI = "moz-abldapdirectory://" + window.opener.gNewServerString;
var theDirectory = MailServices.ab
.getDirectory(targetURI)
.QueryInterface(Ci.nsIAbLDAPDirectory);
theDirectory.maxHits = results;
theDirectory.authDn = document.getElementById("login").value;
theDirectory.saslMechanism = saslMechanism;
window.opener.gNewServer = description;
// set window.opener.gUpdate to true so that LDAP Directory Servers
// dialog gets updated
window.opener.gUpdate = true;
window.arguments[0].newDirectoryUID = theDirectory.UID;
if ("onNewDirectory" in window.arguments[0]) {
window.arguments[0].onNewDirectory(theDirectory);
}
} else {
const addressBookBundle = document.getElementById("bundle_addressBook");
let errorText;
if (errorArg) {
errorText = addressBookBundle.getFormattedString(errorValue, [errorArg]);
} else {
errorText = addressBookBundle.getString(errorValue);
}
Services.prompt.alert(window, document.title, errorText);
event.preventDefault();
}
}

Просмотреть файл

@ -72,7 +72,7 @@ function initLocaleShortDateFormat() {
}
}
} catch (e) {
console.error("initLocaleShortDateFormat: caught an exception: " + e);
console.error("initLocaleShortDateFormat: caught an exception: ", e);
gSearchDateFormat = 0;
}
}
@ -112,7 +112,7 @@ function initializeSearchDateFormat() {
).data == "true";
}
} catch (e) {
console.error("initializeSearchDateFormat: caught an exception: " + e);
console.error("initializeSearchDateFormat: caught an exception: ", e);
gSearchDateFormat = 0;
}

Просмотреть файл

@ -125,7 +125,7 @@ function SetUpTree(forceToServer, getOnlyNew) {
gSubscribeBundle.getString("offlineState")
);
} else {
console.error("Failed to populate subscribe tree: " + e);
console.error("Failed to populate subscribe tree: ", e);
gStatusFeedback.setStatusString(
gSubscribeBundle.getString("errorPopulating")
);

Просмотреть файл

@ -435,10 +435,10 @@ function checkDirectoryIsAllowed(aLocalPath) {
testDir = Services.dirsvc.get(aDirToCheck.dirsvc, Ci.nsIFile);
} catch (e) {
console.error(
"The special folder " +
aDirToCheck.dirsvc +
" cannot be retrieved on this platform: " +
e
"The special folder",
aDirToCheck.dirsvc,
"cannot be retrieved on this platform:",
e
);
}
@ -1522,7 +1522,7 @@ function getFormElementValue(formElement) {
}
return null;
} catch (ex) {
console.error("getFormElementValue failed, ex=" + ex + "\n");
console.error("getFormElementValue failed", ex);
}
return null;
}
@ -1866,9 +1866,7 @@ var gAccountTree = {
// Fetching of this extension panel failed so do not show it,
// just log error.
const extName = data || "(unknown)";
console.error(
"Error accessing panel from extension '" + extName + "': " + e
);
console.error(`Error accessing panel from extension ${extName}`, e);
}
}
amChrome = server.accountManagerChrome;
@ -1876,7 +1874,7 @@ var gAccountTree = {
// Show only a placeholder in the account list saying this account
// is broken, with no child panels.
const accountID = accountName || accountKey;
console.error("Error accessing account " + accountID + ": " + e);
console.error(`Error accessing account ${accountID}`, e);
accountName = "Invalid account " + accountID;
panelsToKeep.length = 0;
validAccount = false;

Просмотреть файл

@ -302,7 +302,7 @@ function finishAccount(account, accountData) {
try {
IID = destServer.protocolInfo.serverIID;
} catch (ex) {
console.error("Could not get IID for " + srcServer.type + ": " + ex);
console.error(`Could not get IID for ${srcServer.type}`, ex);
}
if (IID) {

Просмотреть файл

@ -54,7 +54,7 @@ function onAccept(event) {
saveSmtpSettings(gSmtpServer);
} catch (ex) {
console.error("Error saving smtp server: " + ex);
console.error("Error saving smtp server: ", ex);
}
window.arguments[0].result = true;
@ -155,7 +155,7 @@ function onLockPreference() {
disableIfLocked(allPrefElements);
} catch (e) {
// non-fatal
console.error("Error while getting locked prefs: " + e);
console.error("Error while getting locked prefs: ", e);
}
}

Просмотреть файл

@ -134,7 +134,7 @@ function removeAccount() {
document.getElementById("success").hidden = false;
} catch (ex) {
document.getElementById("failure").hidden = false;
console.error("Failure to remove account: " + ex);
console.error("Failure to remove account: ", ex);
window.arguments[0].result = false;
}
document.getElementById("progress").hidden = true;

Просмотреть файл

@ -64,7 +64,7 @@ runnablePrompter.prototype = {
try {
ok = await this._promiseAuthPrompt(prompter.first);
} catch (ex) {
console.error("runnablePrompter:run: " + ex + "\n");
console.error("runnablePrompter:run: ", ex);
prompter.first.onPromptCanceled();
}
@ -80,9 +80,8 @@ runnablePrompter.prototype = {
} catch (ex) {
// Log the error for extension devs and others to pick up.
console.error(
"runnablePrompter:run: consumer.onPrompt* reported an exception: " +
ex +
"\n"
"runnablePrompter:run: consumer.onPrompt* reported an exception: ",
ex
);
}
}

Просмотреть файл

@ -1096,11 +1096,9 @@ export class MessageSend {
this._sendListener.onStopCopy(0);
}
} catch (e) {
// Ignore the return value of OnStopCopy. Non-zero nsresult will throw
// Ignore the return value of onStopCopy. Non-zero nsresult will throw
// when going through XPConnect. In this case, we don't care about it.
console.warn(
`OnStopCopy failed with 0x${e.result.toString(16)}\n${e.stack}`
);
console.warn("onStopCopy failed", e);
}
this._cleanup();
});

Просмотреть файл

@ -229,7 +229,8 @@ export var MsgUtils = {
).messageURIToMsgHdr(originalMsgURI);
} catch (e) {
console.warn(
`messageServiceFromURI failed for ${originalMsgURI}\n${e.stack}`
`messageServiceFromURI failed for ${originalMsgURI}`,
e.stack
);
}
if (msgHdr) {

Просмотреть файл

@ -600,7 +600,7 @@ ExplainedStatementProcessor.prototype = {
}
},
handleError(aError) {
console.error("Unexpected error in EXPLAIN handler: " + aError);
console.error("Unexpected error in EXPLAIN handler:", aError);
},
handleCompletion() {
const obj = {

Просмотреть файл

@ -155,7 +155,7 @@ export class NntpIncomingServer extends MsgIncomingServer {
} catch (e) {
// Group names with double dot, like alt.binaries.sounds..mp3.zappa are
// not working. Bug 1788572.
console.error(`Failed to add group ${name}. ${e}`);
console.error(`Failed to add group ${name}`, e);
}
}

Просмотреть файл

@ -165,7 +165,7 @@ export class MockEWSServer {
// it does when any error is thrown is respond with a generic 500. To
// makes writing tests with this server a bit easier, we want to log
// the error before responding.
console.error(`Error when processing request: ${e}`);
console.error("Error when processing request:", e);
throw e;
}
}