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

Errors in subflows propagate up to nearest catch node

This commit is contained in:
Nick O'Leary 2015-08-13 22:20:21 +01:00
parent 00c612485b
commit cbdd4de630

View File

@ -68,17 +68,23 @@ function createSubflow(sf,sfn,subflows) {
node.z = sfn.id; node.z = sfn.id;
newNodes.push(node); newNodes.push(node);
} }
// Look for any catch nodes and update their scope ids
// Update all subflow interior wiring to reflect new node IDs // Update all subflow interior wiring to reflect new node IDs
for (i=0;i<newNodes.length;i++) { for (i=0;i<newNodes.length;i++) {
node = newNodes[i]; node = newNodes[i];
var outputs = node.wires; var outputs = node.wires;
for (j=0;j<outputs.length;j++) { for (j=0;j<outputs.length;j++) {
wires = outputs[j]; wires = outputs[j];
for (k=0;k<wires.length;k++) { for (k=0;k<wires.length;k++) {
outputs[j][k] = node_map[outputs[j][k]].id outputs[j][k] = node_map[outputs[j][k]].id
} }
} }
if (node.type === 'catch' && node.scope) {
node.scope = node.scope.map(function(id) {
return node_map[id]?node_map[id].id:""
})
}
} }
// Create a subflow node to accept inbound messages and route appropriately // Create a subflow node to accept inbound messages and route appropriately
@ -226,31 +232,6 @@ function createCatchNodeMap(nodes) {
} }
} }
} }
for (id in nodes) {
if (nodes.hasOwnProperty(id)) {
var m = /^subflow:(.+)$/.exec(nodes[id].type);
if (m) {
subflowInstances[id] = nodes[id];
}
}
}
for (id in subflowInstances) {
if (subflowInstances.hasOwnProperty(id)) {
var z = id;
while(subflowInstances[z]) {
var sfi = subflowInstances[z];
if (!catchNodes[z]) {
z = sfi.z;
} else {
break;
}
}
if (catchNodes[z]) {
catchNodes[id] = catchNodes[id]||[];
catchNodes[id].push(catchNodes[z]);
}
}
}
return catchNodes; return catchNodes;
} }
@ -325,14 +306,16 @@ Flow.prototype.parseConfig = function(config) {
} else { } else {
this.nodes[nodeConfig.id] = nodeInfo; this.nodes[nodeConfig.id] = nodeInfo;
} }
for (var prop in nodeConfig) { if (nodeConfig.type != "catch") {
if (nodeConfig.hasOwnProperty(prop) && for (var prop in nodeConfig) {
prop != "type" && if (nodeConfig.hasOwnProperty(prop) &&
prop != "id" && prop != "type" &&
prop != "z" && prop != "id" &&
prop != "wires" && prop != "z" &&
this.allNodes[nodeConfig[prop]]) { prop != "wires" &&
this.configNodes[nodeConfig[prop]] = this.allNodes[nodeConfig[prop]]; this.allNodes[nodeConfig[prop]]) {
this.configNodes[nodeConfig[prop]] = this.allNodes[nodeConfig[prop]];
}
} }
} }
} }
@ -760,37 +743,39 @@ Flow.prototype.handleError = function(node,logMessage,msg) {
} }
var targetCatchNodes = null; var targetCatchNodes = null;
if (this.catchNodeMap[node.z]) { var throwingNode = node;
targetCatchNodes = this.catchNodeMap[node.z]; var handled = false;
} else if (this.activeNodes[node.z] && this.catchNodeMap[this.activeNodes[node.z].z]) { while (throwingNode && !handled) {
targetCatchNodes = this.catchNodeMap[this.activeNodes[node.z].z]; targetCatchNodes = this.catchNodeMap[throwingNode.z];
} if (targetCatchNodes) {
targetCatchNodes.forEach(function(targetCatchNode) {
if (targetCatchNodes) { if (targetCatchNode.scope && targetCatchNode.scope.indexOf(node.id) === -1) {
targetCatchNodes.forEach(function(targetCatchNode) { return;
console.log(targetCatchNode.scope);
if (targetCatchNode.scope && targetCatchNode.scope.indexOf(node.id) === -1) {
return;
}
var errorMessage;
if (msg) {
errorMessage = redUtil.cloneMessage(msg);
} else {
errorMessage = {};
}
if (errorMessage.hasOwnProperty("error")) {
errorMessage._error = errorMessage.error;
}
errorMessage.error = {
message: logMessage.toString(),
source: {
id: node.id,
type: node.type,
count: count
} }
}; var errorMessage;
targetCatchNode.receive(errorMessage); if (msg) {
}) errorMessage = redUtil.cloneMessage(msg);
} else {
errorMessage = {};
}
if (errorMessage.hasOwnProperty("error")) {
errorMessage._error = errorMessage.error;
}
errorMessage.error = {
message: logMessage.toString(),
source: {
id: node.id,
type: node.type,
count: count
}
};
targetCatchNode.receive(errorMessage);
handled = true;
});
}
if (!handled) {
throwingNode = this.activeNodes[throwingNode.z];
}
} }
} }