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;
newNodes.push(node);
}
// Look for any catch nodes and update their scope ids
// Update all subflow interior wiring to reflect new node IDs
for (i=0;i<newNodes.length;i++) {
node = newNodes[i];
var outputs = node.wires;
for (j=0;j<outputs.length;j++) {
wires = outputs[j];
for (k=0;k<wires.length;k++) {
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
@ -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;
}
@ -325,6 +306,7 @@ Flow.prototype.parseConfig = function(config) {
} else {
this.nodes[nodeConfig.id] = nodeInfo;
}
if (nodeConfig.type != "catch") {
for (var prop in nodeConfig) {
if (nodeConfig.hasOwnProperty(prop) &&
prop != "type" &&
@ -338,6 +320,7 @@ Flow.prototype.parseConfig = function(config) {
}
}
}
}
//console.log("NODES");
//for (i in this.nodes) {
@ -760,15 +743,12 @@ Flow.prototype.handleError = function(node,logMessage,msg) {
}
var targetCatchNodes = null;
if (this.catchNodeMap[node.z]) {
targetCatchNodes = this.catchNodeMap[node.z];
} else if (this.activeNodes[node.z] && this.catchNodeMap[this.activeNodes[node.z].z]) {
targetCatchNodes = this.catchNodeMap[this.activeNodes[node.z].z];
}
var throwingNode = node;
var handled = false;
while (throwingNode && !handled) {
targetCatchNodes = this.catchNodeMap[throwingNode.z];
if (targetCatchNodes) {
targetCatchNodes.forEach(function(targetCatchNode) {
console.log(targetCatchNode.scope);
if (targetCatchNode.scope && targetCatchNode.scope.indexOf(node.id) === -1) {
return;
}
@ -790,7 +770,12 @@ Flow.prototype.handleError = function(node,logMessage,msg) {
}
};
targetCatchNode.receive(errorMessage);
})
handled = true;
});
}
if (!handled) {
throwingNode = this.activeNodes[throwingNode.z];
}
}
}