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

Detect and prevent Catch node loops

This commit is contained in:
Nick O'Leary 2015-06-15 15:09:50 +01:00
parent eae4e3d983
commit c5fd3a5753

View File

@ -744,6 +744,27 @@ function diffFlow(flow,config) {
Flow.prototype.handleError = function(node,logMessage,msg) {
var targetCatchNode = null;
if (this.catchNodeMap[node.z]) {
targetCatchNode = this.catchNodeMap[node.z];
} else if (this.activeNodes[node.z] && this.catchNodeMap[this.activeNodes[node.z].z]) {
targetCatchNode = this.catchNodeMap[this.activeNodes[node.z].z];
}
if (targetCatchNode) {
var count = 1;
if (msg.hasOwnProperty("error")) {
if (msg.error.hasOwnProperty("source")) {
if (msg.error.source.id === node.id) {
count = msg.error.source.count+1;
if (count === 10) {
node.warn("Message exceeded maximum number of catches");
return;
}
}
}
}
var errorMessage;
if (msg) {
errorMessage = redUtil.cloneMessage(msg);
@ -757,15 +778,11 @@ Flow.prototype.handleError = function(node,logMessage,msg) {
message: logMessage.toString(),
source: {
id: node.id,
type: node.type
type: node.type,
count: count
}
};
if (this.catchNodeMap[node.z]) {
this.catchNodeMap[node.z].receive(errorMessage);
} else {
if (this.activeNodes[node.z] && this.catchNodeMap[this.activeNodes[node.z].z]) {
this.catchNodeMap[this.activeNodes[node.z].z].receive(errorMessage);
}
targetCatchNode.receive(errorMessage);
}
}