]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Stop hiding exceptions in WebSock class
authorPierre Ossman <ossman@cendio.se>
Thu, 7 Sep 2017 14:44:01 +0000 (16:44 +0200)
committerPierre Ossman <ossman@cendio.se>
Thu, 7 Sep 2017 15:18:25 +0000 (17:18 +0200)
Let them application decide how to deal with such things and do not
enforce this particular model, which easily hides bugs.

core/websock.js
tests/test.websock.js

index 78809a1ac63eb1ed2486106fdfea1a47d416f4ba..555076bc62283f3721e868bde1f1d266833f069f 100644 (file)
@@ -306,46 +306,18 @@ Websock.prototype = {
     },
 
     _recv_message: function (e) {
-        try {
-            this._decode_message(e.data);
-            if (this.rQlen() > 0) {
-                this._eventHandlers.message();
-                // Compact the receive queue
-                if (this._rQlen == this._rQi) {
-                    this._rQlen = 0;
-                    this._rQi = 0;
-                } else if (this._rQlen > this._rQmax) {
-                    this._expand_compact_rQ();
-                }
-            } else {
-                Log.Debug("Ignoring empty message");
-            }
-        } catch (exc) {
-            var exception_str = "";
-            if (exc.name) {
-                exception_str += "\n    name: " + exc.name + "\n";
-                exception_str += "    message: " + exc.message + "\n";
-            }
-
-            if (typeof exc.description !== 'undefined') {
-                exception_str += "    description: " + exc.description + "\n";
-            }
-
-            if (typeof exc.stack !== 'undefined') {
-                exception_str += exc.stack;
-            }
-
-            if (exception_str.length > 0) {
-                Log.Error("recv_message, caught exception: " + exception_str);
-            } else {
-                Log.Error("recv_message, caught exception: " + exc);
-            }
-
-            if (typeof exc.name !== 'undefined') {
-                this._eventHandlers.error(exc.name + ": " + exc.message);
-            } else {
-                this._eventHandlers.error(exc);
+        this._decode_message(e.data);
+        if (this.rQlen() > 0) {
+            this._eventHandlers.message();
+            // Compact the receive queue
+            if (this._rQlen == this._rQi) {
+                this._rQlen = 0;
+                this._rQi = 0;
+            } else if (this._rQlen > this._rQmax) {
+                this._expand_compact_rQ();
             }
+        } else {
+            Log.Debug("Ignoring empty message");
         }
     }
 };
index 425472c68de2f5117231d13f2b537a7ff9d8b134..5d0f82728dd9915b4e15a8a7fa44bef84c0b7244 100644 (file)
@@ -392,15 +392,6 @@ describe('Websock', function() {
             expect(sock.get_rQi()).to.equal(0);
             expect(sock._rQ.length).to.equal(240);  // keep the invariant that rQbufferSize / 8 >= rQlen
         });
-
-        it('should call the error event handler on an exception', function () {
-            sock._eventHandlers.error = sinon.spy();
-            sock._eventHandlers.message = sinon.stub().throws();
-            var msg = { data: new Uint8Array([1, 2, 3]).buffer };
-            sock._mode = 'binary';
-            sock._recv_message(msg);
-            expect(sock._eventHandlers.error).to.have.been.calledOnce;
-        });
     });
 
     describe('Data encoding', function () {