1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Ensure errors in node.receive are handled

This commit is contained in:
Nick O'Leary 2015-05-02 22:15:33 +01:00
parent 0c5c3448d0
commit 51fce9343b
2 changed files with 19 additions and 1 deletions

View File

@ -193,7 +193,11 @@ Node.prototype.receive = function(msg) {
msg._msgid = constructUniqueIdentifier();
}
this.metric("receive",msg);
this.emit("input", msg);
try {
this.emit("input", msg);
} catch(err) {
this.error(err,msg);
}
};
function log_helper(self, level, msg) {

View File

@ -133,6 +133,20 @@ describe('Node', function() {
});
n.receive(null);
});
it('handles thrown errors', function(done) {
var n = new RedNode({id:'123',type:'abc'});
sinon.stub(n,"error",function(err,msg) {});
var message = {payload:"hello world"};
n.on('input',function(msg) {
throw new Error("test error");
});
n.receive(message);
n.error.called.should.be.true;
n.error.firstCall.args[1].should.equal(message);
done();
});
});
describe('#send', function() {