makeUri: don't throw on invalid uris, return null instead
authorDan Mills <thunder@mozilla.com>
Mon, 03 Nov 2008 14:56:56 -0800
changeset 45016 1399b39e832c9e692a13e8bef3ed89e397b41837
parent 45015 5c9a5123c40cad4e5c55b9451b00437fc1f35ed4
child 45017 9b0b80c80c8a614e113cbb32831977bdc35e103c
push idunknown
push userunknown
push dateunknown
makeUri: don't throw on invalid uris, return null instead
services/sync/modules/util.js
--- a/services/sync/modules/util.js
+++ b/services/sync/modules/util.js
@@ -268,17 +268,17 @@ let Utils = {
       if (typeof(rng) == "object" && code >= rng[0] && code < rng[1])
         return true;
       else if (typeof(rng) == "number" && code == rng) {
         return true;
       }
     }
 
     if (msg) {
-      let log = Log4Moz.Service.getLogger("Service.Util");
+      let log = Log4Moz.repository.getLogger("Service.Util");
       log.error(msg + " Error code: " + code);
     }
 
     return false;
   },
 
   ensureStatus: function Weave_ensureStatus(args) {
     if (!Utils.checkStatus.apply(Utils, arguments))
@@ -307,17 +307,23 @@ let Utils = {
     return hash;
   },
 
   makeURI: function Weave_makeURI(URIString) {
     if (URIString === null || URIString == "")
       return null;
     let ioservice = Cc["@mozilla.org/network/io-service;1"].
       getService(Ci.nsIIOService);
-    return ioservice.newURI(URIString, null, null);
+    try {
+      return ioservice.newURI(URIString, null, null);
+    } catch (e) {
+      let log = Log4Moz.repository.getLogger("Service.Util");
+      log.debug("Could not create URI: " + e);
+      return null;
+    }
   },
 
   xpath: function Weave_xpath(xmlDoc, xpathString) {
     let root = xmlDoc.ownerDocument == null ?
       xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement;
     let nsResolver = xmlDoc.createNSResolver(root);
 
     return xmlDoc.evaluate(xpathString, xmlDoc, nsResolver,
@@ -430,17 +436,17 @@ let Utils = {
   /*
    * Event listener object
    * Used to handle XMLHttpRequest and nsITimer callbacks
    */
 
   EventListener: function Weave_EventListener(handler, eventName) {
     this._handler = handler;
     this._eventName = eventName;
-    this._log = Log4Moz.Service.getLogger("Async.EventHandler");
+    this._log = Log4Moz.repository.getLogger("Async.EventHandler");
     this._log.level =
       Log4Moz.Level[Utils.prefs.getCharPref("log.logger.async")];
   }
 };
 
 Utils.EventListener.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback, Ci.nsISupports]),