summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolly Ross <sross@redhat.com>2015-08-06 15:06:29 -0400
committerSolly Ross <sross@redhat.com>2015-08-06 15:14:22 -0400
commitb084d0a4075a3254df76affa6e39ab21105045a8 (patch)
tree40922621f02a2ffd3a26241eb5dc672b888e93ac
parentf00193e08f7c55a7b0b55556ef96b10b41dd3bc3 (diff)
downloadnovnc-tmp-branch/throw-error-on-error.tar.gz
Actually throw errors in teststmp-branch/throw-error-on-error
-rw-r--r--include/rfb.js2
-rw-r--r--include/util.js2
-rw-r--r--include/websock.js27
-rw-r--r--tests/test.rfb.js6
-rw-r--r--tests/test.websock.js15
5 files changed, 25 insertions, 27 deletions
diff --git a/include/rfb.js b/include/rfb.js
index b7a811d..d5bf0c2 100644
--- a/include/rfb.js
+++ b/include/rfb.js
@@ -167,7 +167,7 @@ var RFB;
try {
this._display = new Display({target: this._target});
} catch (exc) {
- Util.Error("Display exception: " + exc);
+ Util.Error("Display exception:", exc);
throw exc;
}
diff --git a/include/util.js b/include/util.js
index ed0e3cd..1ebeefe 100644
--- a/include/util.js
+++ b/include/util.js
@@ -217,7 +217,7 @@ Util.init_logging = function (level) {
case 'warn':
Util.Warn = function (msg) { console.warn(msg); };
case 'error':
- Util.Error = function (msg) { console.error(msg); };
+ Util.Error = function (msg, err) { console.error(msg, err); };
case 'none':
break;
default:
diff --git a/include/websock.js b/include/websock.js
index 61d9467..cb91500 100644
--- a/include/websock.js
+++ b/include/websock.js
@@ -375,31 +375,8 @@ function Websock() {
Util.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) {
- Util.Error("recv_message, caught exception: " + exception_str);
- } else {
- Util.Error("recv_message, caught exception: " + exc);
- }
-
- if (typeof exc.name !== 'undefined') {
- this._eventHandlers.error(exc.name + ": " + exc.message);
- } else {
- this._eventHandlers.error(exc);
- }
+ Util.Error("recv_message, caught exception:", exc);
+ this._eventHandlers.error(exc)
}
}
};
diff --git a/tests/test.rfb.js b/tests/test.rfb.js
index 961d9eb..e8691bf 100644
--- a/tests/test.rfb.js
+++ b/tests/test.rfb.js
@@ -32,6 +32,12 @@ describe('Remote Frame Buffer Protocol Client', function() {
this._rQ = rQ;
};
+ // Actually throw errors
+ if (Util.__Error === undefined) { Util.__Error = Util.Error; }
+ Util.Error = function (msg, err) {
+ if (err) { throw err; }
+ Util.__Error(msg, err);
+ };
});
after(function () {
diff --git a/tests/test.websock.js b/tests/test.websock.js
index 14d5783..01ea766 100644
--- a/tests/test.websock.js
+++ b/tests/test.websock.js
@@ -7,6 +7,19 @@ var expect = chai.expect;
describe('Websock', function() {
"use strict";
+ function throwUtilError() {
+ if (Util.__Error === undefined) { Util.__Error = Util.Error; }
+ Util.Error = function (msg, err) {
+ if (err) { throw err; }
+ Util.__Error(msg, err);
+ };
+ }
+
+ before(function () {
+ // Actually throw errors
+ throwUtilError();
+ });
+
describe('Queue methods', function () {
var sock;
var RQ_TEMPLATE = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
@@ -405,12 +418,14 @@ describe('Websock', function() {
});
it('should call the error event handler on an exception', function () {
+ Util.Error = Util.__Error;
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;
+ throwUtilError();
});
});