Bug 411680: Always show more details about update check failures in the error console. r=robstrong
authorDave Townsend <dtownsend@oxymoronical.com>
Wed, 19 Aug 2009 11:32:15 +0100
changeset 31679 325a834b759c3f96be465ab55c475bb81842d6d8
parent 31678 567f5aa9792f9349a7d75039d2180e54d4583113
child 31680 9f8181d17a140deae97c34e9d85870c68b1771db
push id8663
push userdtownsend@mozilla.com
push dateThu, 20 Aug 2009 09:45:01 +0000
treeherdermozilla-central@325a834b759c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobstrong
bugs411680
milestone1.9.3a1pre
Bug 411680: Always show more details about update check failures in the error console. r=robstrong
toolkit/mozapps/extensions/src/nsExtensionManager.js.in
--- a/toolkit/mozapps/extensions/src/nsExtensionManager.js.in
+++ b/toolkit/mozapps/extensions/src/nsExtensionManager.js.in
@@ -517,35 +517,62 @@ function removeDirRecursive(dir) {
       entry.remove(false);
     }
   }
   dir.permissions = PERMS_DIRECTORY;
   dir.remove(true);
 }
 
 /**
- * Logs a string to the error console.
+ * Logs a string to the error console and the text console if logging is
+ * enabled.
  * @param   string
- *          The string to write to the error console.
+ *          The log message.
  */
 function LOG(string) {
   if (gLoggingEnabled) {
-    dump("*** " + string + "\n");
+    dump("*** EM_LOG *** " + string + "\n");
     if (gConsole)
       gConsole.logStringMessage(string);
   }
 }
 
 /**
- * Logs a string to the error console and to a permanent log file. 
+ * Logs a warning to the error console and if logging is enabled to the text
+ * console.
  * @param   string
- *          The string to write out.
+ *          The warning message.
+ */
+function WARN(string) {
+  if (gLoggingEnabled)
+    dump("*** EM_WARN *** " + string + "\n");
+  if (gConsole) {
+    var message = Cc["@mozilla.org/scripterror;1"].
+                  createInstance(Ci.nsIScriptError);
+    message.init(string, null, null, 0, 0, Ci.nsIScriptError.warningFlag,
+                 "component javascript");
+    gConsole.logMessage(message);
+  }
+}
+
+/**
+ * Logs an error to the error console and to a permanent log file.
+ * @param   string
+ *          The error message.
  */  
 function ERROR(string) {
-  LOG(string);
+  if (gLoggingEnabled)
+    dump("*** EM_ERROR *** " + string + "\n");
+  if (gConsole) {
+    var message = Cc["@mozilla.org/scripterror;1"].
+                  createInstance(Ci.nsIScriptError);
+    message.init(string, null, null, 0, 0, Ci.nsIScriptError.errorFlag,
+                 "component javascript");
+    gConsole.logMessage(message);
+  }
   try {
     var tstamp = new Date();
     var logfile = getFile(KEY_PROFILEDIR, [FILE_EXTENSIONS_LOG]);
     var stream = Cc["@mozilla.org/network/file-output-stream;1"].
                  createInstance(Ci.nsIFileOutputStream);
     stream.init(logfile, 0x02 | 0x08 | 0x10, 0666, 0); // write, create, append
     var writer = Cc["@mozilla.org/intl/converter-output-stream;1"].
                  createInstance(Ci.nsIConverterOutputStream);
@@ -5905,18 +5932,18 @@ RDFItemUpdater.prototype = {
 
     dsURI = escapeAddonURI(aItem, this._updater._appVersion, dsURI, emDS);
 
     // Verify that the URI provided is valid
     try {
       var uri = newURI(dsURI);
     }
     catch (e) {
-      LOG("RDFItemUpdater:checkForUpdates: There was an error loading the \r\n" +
-          " update datasource for: " + dsURI + ", item = " + aItem.id + ", error: " + e);
+      WARN("RDFItemUpdater:checkForUpdates: There was an error loading the \r\n" +
+           " update datasource for: " + dsURI + ", item = " + aItem.id + ", error: " + e);
       this._updater.checkForDone(aItem,
                                  Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
       return;
     }
 
     LOG("RDFItemUpdater:checkForUpdates sending a request to server for: " +
         uri.spec + ", item = " + aItem.objectSource);
 
@@ -5991,18 +6018,18 @@ RDFItemUpdater.prototype = {
     }
     catch (e) {
       status = 0;
     }
     // When status is 0 we don't have a valid channel.
     if (status == 0)
       statusText = "nsIXMLHttpRequest channel unavailable";
 
-    LOG("RDFItemUpdater:onError: There was an error loading the \r\n" +
-        "the update datasource for item " + aItem.id + ", error: " + statusText);
+    WARN("RDFItemUpdater:onError: There was an error loading the \r\n" +
+         "the update datasource for item " + aItem.id + ", error: " + statusText);
     this._updater.checkForDone(aItem,
                                Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
   },
 
   onDatasourceLoaded: function RDFItemUpdater_onDatasourceLoaded(aDatasource, aLocalItem) {
     /*
 #      The extension update RDF file looks something like this:
 #
@@ -6067,39 +6094,39 @@ RDFItemUpdater.prototype = {
       if (signature) {
         var serializer = new RDFSerializer();
         try {
           var updateString = serializer.serializeResource(aDatasource, extensionRes);
           var verifier = Cc["@mozilla.org/security/datasignatureverifier;1"].
                          getService(Ci.nsIDataSignatureVerifier);
           try {
             if (!verifier.verifyData(updateString, signature, aLocalItem.updateKey)) {
-              LOG("RDFItemUpdater:onDatasourceLoaded: Update manifest for " +
-                  aLocalItem.id + " failed signature check.");
+              WARN("RDFItemUpdater:onDatasourceLoaded: Update manifest for " +
+                   aLocalItem.id + " failed signature check.");
               this._updater.checkForDone(aLocalItem, Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
               return;
             }
           }
           catch (e) {
-            LOG("RDFItemUpdater:onDatasourceLoaded: Failed to verify signature for " +
-                aLocalItem.id + ". This indicates a malformed update key or signature.");
+            WARN("RDFItemUpdater:onDatasourceLoaded: Failed to verify signature for " +
+                 aLocalItem.id + ". This indicates a malformed update key or signature.");
             this._updater.checkForDone(aLocalItem, Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
             return;
           }
         }
         catch (e) {
-          LOG("RDFItemUpdater:onDatasourceLoaded: Failed to generate signature " +
-              "string for " + aLocalItem.id + ". Serializer threw " + e);
+          WARN("RDFItemUpdater:onDatasourceLoaded: Failed to generate signature " +
+               "string for " + aLocalItem.id + ". Serializer threw " + e);
           this._updater.checkForDone(aLocalItem, Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
           return;
         }
       }
       else {
-        LOG("RDFItemUpdater:onDatasourceLoaded: Update manifest for " +
-            aLocalItem.id + " did not contain a signature.");
+        WARN("RDFItemUpdater:onDatasourceLoaded: Update manifest for " +
+             aLocalItem.id + " did not contain a signature.");
         this._updater.checkForDone(aLocalItem, Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
         return;
       }
     }
     /* If there is no updateKey either the update was over SSL, or it is an old
      * addon that we are allowing a grace update. */
 
     // Parse the response RDF
@@ -6198,25 +6225,25 @@ RDFItemUpdater.prototype = {
 
     var updatesArc = gRDF.GetResource(EM_NS("updates"));
     var updates = aDataSource.GetTarget(extensionRes, updatesArc, true);
 
     try {
       updates = updates.QueryInterface(Ci.nsIRDFResource);
     }
     catch (e) {
-      LOG("RDFItemUpdater:_parseV20UpdateInfo: No updates were found for:\r\n" +
-          aLocalItem.id + "\r\n" +
-          "If you are an Extension developer and were expecting there to be\r\n" +
-          "updates, this could mean any number of things, since the RDF system\r\n" +
-          "doesn't give up much in the way of information when the load fails.\r\n" +
-          "\r\nTry checking that: \r\n" +
-          " 1. Your RDF File is correct - e.g. check that there is a top level\r\n" +
-          "    RDF Resource with a URI urn:mozilla:extension:{GUID}, and that\r\n" +
-          "    the <em:updates> listed all have matching GUIDs.");
+      WARN("RDFItemUpdater:_parseV20UpdateInfo: No updates were found for:\r\n" +
+           aLocalItem.id + "\r\n" +
+           "If you are an Extension developer and were expecting there to be\r\n" +
+           "updates, this could mean any number of things, since the RDF system\r\n" +
+           "doesn't give up much in the way of information when the load fails.\r\n" +
+           "\r\nTry checking that: \r\n" +
+           " 1. Your RDF File is correct - e.g. check that there is a top level\r\n" +
+           "    RDF Resource with a URI urn:mozilla:extension:{GUID}, and that\r\n" +
+           "    the <em:updates> listed all have matching GUIDs.");
       return null;
     }
 
     // Track the newest update found
     var updatedItem = null;
 
     var cu = Cc["@mozilla.org/rdf/container-utils;1"].
              getService(Ci.nsIRDFContainerUtils);
@@ -6297,19 +6324,19 @@ RDFItemUpdater.prototype = {
           continue;
 
         /* If the update link is non-ssl and we do not have a hash or the hash
          * is of an insecure nature then we must ignore this update. Bypass
          * this if not checking update security. Currently we only consider
          * the sha hashing algorithms as secure. */
         if (gCheckUpdateSecurity && updateLink.substring(0, 6) != "https:" && 
             (!updateHash || updateHash.substring(0, 3) != "sha")) {
-          LOG("RDFItemUpdater:_parseV20Update: Update for " + aLocalItem.id +
-              " at " + updateLink + " ignored because it is insecure. updateLink " +
-              " must be a https url or an updateHash must be specified.");
+          WARN("RDFItemUpdater:_parseV20Update: Update for " + aLocalItem.id +
+               " at " + updateLink + " ignored because it is insecure. updateLink " +
+               " must be a https url or an updateHash must be specified.");
           continue;
         }
       }
 
       var updatedItem = makeItem(aLocalItem.id,
                                  version,
                                  aLocalItem.installLocationKey,
                                  this._getPropertyFromResource(aDataSource, targetApp, "minVersion", aLocalItem),