From: Pierre Ossman Date: Thu, 7 Sep 2017 14:44:01 +0000 (+0200) Subject: Stop hiding exceptions in WebSock class X-Git-Tag: v1.0.0~85^2~10 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=1678bf860fd0505baa955aeb1bf24cadc166ad2b;p=mirror_novnc.git Stop hiding exceptions in WebSock class Let them application decide how to deal with such things and do not enforce this particular model, which easily hides bugs. --- diff --git a/core/websock.js b/core/websock.js index 78809a1..555076b 100644 --- a/core/websock.js +++ b/core/websock.js @@ -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"); } } }; diff --git a/tests/test.websock.js b/tests/test.websock.js index 425472c..5d0f827 100644 --- a/tests/test.websock.js +++ b/tests/test.websock.js @@ -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 () {