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.
This commit is contained in:
Pierre Ossman 2017-09-07 16:44:01 +02:00
parent a49ade5fa0
commit 1678bf860f
2 changed files with 11 additions and 48 deletions

View File

@ -306,7 +306,6 @@ Websock.prototype = {
},
_recv_message: function (e) {
try {
this._decode_message(e.data);
if (this.rQlen() > 0) {
this._eventHandlers.message();
@ -320,32 +319,5 @@ Websock.prototype = {
} 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);
}
}
}
};

View 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 () {