Bug 920801 - Port chat/ changes from Instantbird to comm-central - 6 - Bio 2153 - Make UTF-8 conversion warnings less noisy, r=clokep.
authoraleth <aleth@instantbird.org>
Fri, 13 Sep 2013 00:27:46 +0200
changeset 17237 7f24d4cea1c92cb5a97b5b3f8b1ed7af339641a7
parent 17236 a0fde7f219422e90c6c0f53bef678c15224deb61
child 17238 c47804c65bb49b7def37f785eaebe046bb785fbf
push id1103
push usermbanner@mozilla.com
push dateTue, 18 Mar 2014 07:44:06 +0000
treeherdercomm-beta@50c6279a0af0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersclokep
bugs920801
Bug 920801 - Port chat/ changes from Instantbird to comm-central - 6 - Bio 2153 - Make UTF-8 conversion warnings less noisy, r=clokep.
chat/protocols/irc/irc.js
chat/protocols/irc/ircHandlers.jsm
--- a/chat/protocols/irc/irc.js
+++ b/chat/protocols/irc/irc.js
@@ -651,48 +651,55 @@ ircSocket.prototype = {
       delete this._converter;
       this.ERROR("Failed to set character set to: " + this._account._encoding +
                  " for " + this._account.name + ".");
     }
   },
 
   // Implement Section 5 of RFC 2812.
   onDataReceived: function(aRawMessage) {
-    this.DEBUG(aRawMessage);
+    let conversionWarning = "";
     if (this._converter) {
       try {
         aRawMessage = this._converter.ConvertToUnicode(aRawMessage);
       } catch (e) {
-        this.WARN("This message doesn't seem to be " + this._account._encoding +
-                  " encoded: " + aRawMessage);
+        conversionWarning = "\nThis message doesn't seem to be " +
+                            this._account._encoding + " encoded.";
         // Unfortunately, if the unicode converter failed once,
         // it will keep failing so we need to reinitialize it.
         this._initCharsetConverter();
       }
     }
 
     // We've received data and are past the authentication stage.
     if (this._account.connected)
       this.resetPingTimer();
 
     // Low level dequote: replace quote character \020 followed by 0, n, r or
     // \020 with a \0, \n, \r or \020, respectively. Any other character is
     // replaced with itself.
     const lowDequote = {"0": "\0", "n": "\n", "r": "\r", "\x10": "\x10"};
-    aRawMessage = aRawMessage.replace(/\x10./g,
+    let dequotedMessage = aRawMessage.replace(/\x10./g,
       function(aStr) lowDequote[aStr[1]] || aStr[1]);
 
     try {
-      // If nothing handled the message, throw a warning.
-      if (!ircHandlers.handleMessage(this._account, new ircMessage(aRawMessage)))
-        this.WARN("Unhandled IRC message: " + aRawMessage);
+      let message = new ircMessage(dequotedMessage);
+      let isHandled = ircHandlers.handleMessage(this._account, message);
+      message.rawMessage = aRawMessage; // Log the quoted message.
+      let logEntry = JSON.stringify(message) + conversionWarning;
+      // Log the message if it was handled, otherwise throw a warning.
+      if (isHandled)
+        this.DEBUG(logEntry);
+      else
+        this.WARN("Unhandled IRC message:\n" + logEntry);
     } catch (e) {
       // Catch the error, display it and hope the connection can continue with
       // this message in error. Errors are also caught inside of handleMessage,
       // but we expect to handle message parsing errors here.
+      this.DEBUG(aRawMessage + conversionWarning);
       this.ERROR(e);
     }
   },
   onConnection: function() {
     this._account._connectionRegistration.call(this._account);
   },
   disconnect: function() {
     if (!this._account)
--- a/chat/protocols/irc/ircHandlers.jsm
+++ b/chat/protocols/irc/ircHandlers.jsm
@@ -86,17 +86,16 @@ var ircHandlers = {
 
   registerServicesHandler: function(aHandler)
     this._registerHandler(this._servicesHandlers, aHandler),
   unregisterServicesHandler: function(aHandler)
     this._unregisterHandler(this._servicesHandlers, aHandler),
 
   // Handle a message based on a set of handlers.
   _handleMessage: function(aHandlers, aAccount, aMessage, aCommand) {
-    aAccount.DEBUG(JSON.stringify(aMessage));
     // Loop over each handler and run the command until one handles the message.
     for each (let handler in aHandlers) {
       try {
         // Attempt to execute the command, by checking if the handler has the
         // command.
         // Parse the command with the JavaScript account object as "this".
         if (handler.isEnabled.call(aAccount) &&
             Object.prototype.hasOwnProperty.call(handler.commands, aCommand) &&