'Fork' operation now has an option to ignore errors occuring on each branch

This commit is contained in:
n1474335 2017-01-16 15:58:38 +00:00
parent 488ca7167e
commit baa433ab80
3 changed files with 33 additions and 16 deletions

View file

@ -62,6 +62,11 @@ var OperationConfig = {
name: "Merge delimiter", name: "Merge delimiter",
type: "binary_short_string", type: "binary_short_string",
value: FlowControl.MERGE_DELIM value: FlowControl.MERGE_DELIM
},
{
name: "Ignore errors",
type: "boolean",
value: FlowControl.FORK_IGNORE_ERRORS
} }
] ]
}, },

View file

@ -19,6 +19,11 @@ var FlowControl = {
* @default * @default
*/ */
MERGE_DELIM: "\\n", MERGE_DELIM: "\\n",
/**
* @constant
* @default
*/
FORK_IGNORE_ERRORS: false,
/** /**
* Fork operation. * Fork operation.
@ -30,15 +35,16 @@ var FlowControl = {
* @returns {Object} The updated state of the recipe. * @returns {Object} The updated state of the recipe.
*/ */
run_fork: function(state) { run_fork: function(state) {
var op_list = state.op_list, var op_list = state.op_list,
input_type = op_list[state.progress].input_type, input_type = op_list[state.progress].input_type,
output_type = op_list[state.progress].output_type, output_type = op_list[state.progress].output_type,
input = state.dish.get(input_type), input = state.dish.get(input_type),
ings = op_list[state.progress].get_ing_values(), ings = op_list[state.progress].get_ing_values(),
split_delim = ings[0], split_delim = ings[0],
merge_delim = ings[1], merge_delim = ings[1],
sub_op_list = [], ignore_errors = ings[2],
inputs = []; sub_op_list = [],
inputs = [];
if (input) if (input)
inputs = input.split(split_delim); inputs = input.split(split_delim);
@ -55,14 +61,21 @@ var FlowControl = {
var recipe = new Recipe(), var recipe = new Recipe(),
output = "", output = "",
progress; progress = 0;
recipe.add_operations(sub_op_list); recipe.add_operations(sub_op_list);
// Run recipe over each tranche // Run recipe over each tranche
for (i = 0; i < inputs.length; i++) { for (i = 0; i < inputs.length; i++) {
var dish = new Dish(inputs[i], input_type); var dish = new Dish(inputs[i], input_type);
progress = recipe.execute(dish, 0); try {
progress = recipe.execute(dish, 0);
} catch(err) {
if (!ignore_errors) {
throw err;
}
progress = err.progress + 1;
}
output += dish.get(output_type) + merge_delim; output += dish.get(output_type) + merge_delim;
} }

View file

@ -177,13 +177,12 @@ Recipe.prototype.execute = function(dish, start_from) {
var e = typeof err == "string" ? { message: err } : err; var e = typeof err == "string" ? { message: err } : err;
e.progress = i; e.progress = i;
e.display_str = op.name + " - ";
if (e.fileName) { if (e.fileName) {
e.display_str += e.name + " in " + e.fileName + e.display_str = op.name + " - " + e.name + " in " +
" on line " + e.lineNumber + e.fileName + " on line " + e.lineNumber +
".<br><br>Message: " + e.message; ".<br><br>Message: " + (e.display_str || e.message);
} else { } else {
e.display_str += e.message; e.display_str = op.name + " - " + (e.display_str || e.message);
} }
throw e; throw e;