mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Ensure errors in node.receive are handled
This commit is contained in:
		@@ -193,7 +193,11 @@ Node.prototype.receive = function(msg) {
 | 
				
			|||||||
        msg._msgid = constructUniqueIdentifier();
 | 
					        msg._msgid = constructUniqueIdentifier();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.metric("receive",msg);
 | 
					    this.metric("receive",msg);
 | 
				
			||||||
 | 
					    try { 
 | 
				
			||||||
        this.emit("input", msg);
 | 
					        this.emit("input", msg);
 | 
				
			||||||
 | 
					    } catch(err) {
 | 
				
			||||||
 | 
					        this.error(err,msg);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function log_helper(self, level, msg) {
 | 
					function log_helper(self, level, msg) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -133,6 +133,20 @@ describe('Node', function() {
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
            n.receive(null);
 | 
					            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() {
 | 
					    describe('#send', function() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user