Bug 953454 - report startup failures in an understandable way. Patch by Romain Bezut <romain@bezut.info>
authorFlorian Quèze <florian@instantbird.org>
Mon, 25 Aug 2008 15:05:34 +0200
changeset 13775 e77bc68f799491a7643353f14c79a10d059a1763
parent 13774 99a0c022b45a1e4d01c4e490f2c6996f21ca0cbb
child 13776 f444b7b74b5ec54ac414cc28e6ad334f8e11c046
push id9778
push userflorian@queze.net
push dateSun, 12 Jan 2014 18:25:45 +0000
treeherdercomm-central@f81a23bfefcd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs953454
Bug 953454 - report startup failures in an understandable way. Patch by Romain Bezut <romain@bezut.info>
im/base/content/instantbird/blist.js
im/base/content/instantbird/blist.xul
im/base/content/instantbird/core.js
im/base/content/jar.mn
im/locales/en-US/chrome/instantbird/core.properties
im/locales/jar.mn
--- a/im/base/content/instantbird/blist.js
+++ b/im/base/content/instantbird/blist.js
@@ -170,17 +170,21 @@ var buddyList = {
       Components.classes["@mozilla.org/xre/app-info;1"]
                 .getService(Components.interfaces.nsICrashReporter)
                 .annotateCrashReport("Vendor", "Instantbird");
     } catch(e) {
       // This can fail if breakpad isn't enabled,
       // don't worry too much about this exception.
     }
 
-    initPurpleCore();
+    if (!initPurpleCore()) {
+      window.close();
+      return;
+    }
+
     buddyList.checkNotDisconnected();
     buddyList.checkForIrcAccount();
     addObservers(buddyList, events);
     this.addEventListener("unload", buddyList.unload, false);
   },
   unload: function bl_unload() {
     removeObservers(buddyList, events);
     uninitPurpleCore();
@@ -234,33 +238,9 @@ var buddyList = {
         if (item.localName == "buddy")
           item.openConversation();
         break;
     }
     return;
   }
 };
 
-function initPurpleCore()
-{
-  try {
-    var pcs = Components.classes["@instantbird.org/purple/core;1"]
-                        .getService(Ci.purpleICoreService);
-    pcs.init();
-  }
-  catch (e) {
-    alert(e);
-  }
-}
-
-function uninitPurpleCore()
-{
-  try {
-    var pcs = Components.classes["@instantbird.org/purple/core;1"]
-                        .getService(Ci.purpleICoreService);
-    pcs.quit();
-  }
-  catch (e) {
-    alert(e);
-  }
-}
-
 this.addEventListener("load", buddyList.load, false);
--- a/im/base/content/instantbird/blist.xul
+++ b/im/base/content/instantbird/blist.xul
@@ -52,16 +52,17 @@
   id     = "instantbird"
   windowtype="Messenger:blist"
   title  = "&blist.title;"
   width  = "200"
   height = "600"
   persist= "width height screenX screenY"
   xmlns  = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript" src="chrome://instantbird/content/utilities.js"/>
+  <script type="application/javascript" src="chrome://instantbird/content/core.js"/>
   <script type="application/javascript" src="chrome://instantbird/content/blist.js"/>
   <script type="application/javascript" src="chrome://instantbird/content/menus.js"/>
   <script type="application/javascript" src="chrome://instantbird/content/sound.js"/>
 
   <stringbundle id="awayBundle" src="chrome://instantbird/locale/away.properties"/>
 
   <commandset id="maincommandset">
     <command id="accountmanager" oncommand="menus.accounts()"/>
new file mode 100644
--- /dev/null
+++ b/im/base/content/instantbird/core.js
@@ -0,0 +1,103 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Instantbird messenging client, released
+ * 2007.
+ *
+ * The Initial Developer of the Original Code is
+ * Florian QUEZE <florian@instantbird.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Romain Bezut <romain@bezut.info>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+function initPurpleCore()
+{
+  if (!Ci.purpleICoreService) {
+    promptError("startupFailure.purplexpcomFileError");
+    return false;
+  }
+
+  if (!Components.classes["@instantbird.org/purple/core;1"]) {
+    promptError("startupFailure.xpcomRegistrationError");
+    return false;
+  }
+
+  try {
+    var pcs = Components.classes["@instantbird.org/purple/core;1"]
+                        .getService(Ci.purpleICoreService);
+    pcs.init();
+  }
+  catch (e) {
+    promptError("startupFailure.purplexpcomInitError", e);
+    return false;
+  }
+
+  if (!pcs.version) {
+    promptError("startupFailure.libpurpleError");
+    return false;
+  }
+
+  if (!pcs.getProtocols().hasMoreElements()) {
+    promptError("startupFailure.noProtocolLoaded");
+    uninitPurpleCore();
+    return false;
+  }
+
+  return true;
+}
+
+function uninitPurpleCore()
+{
+  try {
+    var pcs = Components.classes["@instantbird.org/purple/core;1"]
+                        .getService(Ci.purpleICoreService);
+    pcs.quit();
+  }
+  catch (e) {
+    var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+                            .getService(Components.interfaces.nsIPromptService);
+
+    prompts.alert(null, "Shutdown Error", "An error occurred while shutting down purplexpcom: " + e);
+  }
+}
+
+function promptError(aKeyString, aMessage) {
+  var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+                          .getService(Components.interfaces.nsIPromptService);
+
+  var bundle =  Components.classes["@mozilla.org/intl/stringbundle;1"]
+                          .getService(Components.interfaces.nsIStringBundleService)
+                          .createBundle("chrome://instantbird/locale/core.properties");
+
+  var title = bundle.GetStringFromName("startupFailure.title");
+  var message = bundle.GetStringFromName("startupFailure.apologize") + "\n\n";
+  message += aMessage ? bundle.formatStringFromName(aKeyString, [aMessage], 1)
+                      : bundle.GetStringFromName(aKeyString);
+  prompts.alert(null, title, message);
+}
--- a/im/base/content/jar.mn
+++ b/im/base/content/jar.mn
@@ -17,16 +17,17 @@ instantbird.jar:
 	content/instantbird/account.xul		(instantbird/account.xul)
 	content/instantbird/addbuddy.js		(instantbird/addbuddy.js)
 	content/instantbird/addbuddy.xul	(instantbird/addbuddy.xul)
 	content/instantbird/anim.xml		(instantbird/anim.xml)
 	content/instantbird/blist.css		(instantbird/blist.css)
 	content/instantbird/blist.js		(instantbird/blist.js)
 	content/instantbird/blist.xul		(instantbird/blist.xul)
 	content/instantbird/buddy.xml		(instantbird/buddy.xml)
+	content/instantbird/core.js		(instantbird/core.js)
 	content/instantbird/conversation.xml	(instantbird/conversation.xml)
 	content/instantbird/conv.html		(instantbird/conv.html)
 	content/instantbird/credits.xhtml	(instantbird/credits.xhtml)
 	content/instantbird/group.xml		(instantbird/group.xml)
 	content/instantbird/instantbird.css	(instantbird/instantbird.css)
 	content/instantbird/instantbird.js	(instantbird/instantbird.js)
 	content/instantbird/instantbird.xul	(instantbird/instantbird.xul)
 	content/instantbird/joinchat.js		(instantbird/joinchat.js)
new file mode 100644
--- /dev/null
+++ b/im/locales/en-US/chrome/instantbird/core.properties
@@ -0,0 +1,8 @@
+startupFailure.title=Instantbird - Start up failure
+startupFailure.apologize=Instantbird encountered an error during start-up and must close, we apologize for the inconvenience.
+
+startupFailure.purplexpcomFileError=Description: The file "purplexpcom.xpt" is missing or corrupted.
+startupFailure.xpcomRegistrationError=Description: XPCOM registration of the purplexpcom component failed.
+startupFailure.purplexpcomInitError=An exception occurred while initializing purplexpcom: %S
+startupFailure.libpurpleError=An error occurred while checking whether libpurple is usable.
+startupFailure.noProtocolLoaded=Description: No protocol plugin could be loaded.
--- a/im/locales/jar.mn
+++ b/im/locales/jar.mn
@@ -5,18 +5,18 @@
 	locale/@AB_CD@/instantbird/aboutDialog.dtd	(%chrome/instantbird/aboutDialog.dtd)
 	locale/@AB_CD@/instantbird/account.dtd		(%chrome/instantbird/account.dtd)
 	locale/@AB_CD@/instantbird/accounts.dtd		(%chrome/instantbird/accounts.dtd)
 	locale/@AB_CD@/instantbird/accounts.properties	(%chrome/instantbird/accounts.properties)
 	locale/@AB_CD@/instantbird/accountWizard.dtd	(%chrome/instantbird/accountWizard.dtd)
 	locale/@AB_CD@/instantbird/addbuddy.dtd		(%chrome/instantbird/addbuddy.dtd)
 	locale/@AB_CD@/instantbird/away.properties	(%chrome/instantbird/away.properties)
 	locale/@AB_CD@/instantbird/buddy.dtd		(%chrome/instantbird/buddy.dtd)
+	locale/@AB_CD@/instantbird/core.properties	(%chrome/instantbird/core.properties)
 	locale/@AB_CD@/instantbird/credits.dtd		(%chrome/instantbird/credits.dtd)
 	locale/@AB_CD@/instantbird/instantbird.dtd	(%chrome/instantbird/instantbird.dtd)
 	locale/@AB_CD@/instantbird/joinChat.dtd		(%chrome/instantbird/joinChat.dtd)
 	locale/@AB_CD@/instantbird/proxies.dtd		(%chrome/instantbird/proxies.dtd)
 	locale/@AB_CD@/instantbird/proxies.properties	(%chrome/instantbird/proxies.properties)
 	locale/@AB_CD@/instantbird/prpl.properties	(%chrome/instantbird/prpl.properties)
 % locale branding @AB_CD@ %locale/@AB_CD@/branding/
 	locale/@AB_CD@/branding/brand.dtd		(%chrome/branding/brand.dtd)
 	locale/@AB_CD@/branding/brand.properties	(%chrome/branding/brand.properties)
-