Started error handling

This commit is contained in:
Tim Stallard 2017-03-13 17:55:11 +00:00
parent eb26bea14e
commit 38cb7b7d75
2 changed files with 30 additions and 21 deletions

View File

@ -9,15 +9,15 @@ module.exports = {
}, },
a: { a: {
name: "a", name: "a",
type: "text", type: "number",
required: true, required: true,
inline: false inline: true
}, },
b: { b: {
name: "b", name: "b",
type: "text", type: "number",
required: true, required: true,
inline: false inline: true
} }
}, },
output: true, output: true,
@ -33,7 +33,7 @@ module.exports = {
} }
if(!require("./util/coPrime.js")(a, 26)){ if(!require("./util/coPrime.js")(a, 26)){
console.log(a, 26, "not coprime"); throw "a and 26 must be coprime";
return ""; return "";
} }

View File

@ -3,26 +3,35 @@ var events = require("./events.js");
var blocks = require("./blocks"); var blocks = require("./blocks");
function resolveOutput(block, cache){ function resolveOutput(block, cache){
var inputValues = {}; try{
for(var input in block.inputs){ var inputValues = {};
if(block.inputs[input].joined){ //if it's joined to something else var error = "";
if(block.inputs[input].joined in cache){ //if output of other block is already in cache for(var input in block.inputs){
inputValues[input] = cache[block.inputs[input].joined]; if(block.inputs[input].joined){ //if it's joined to something else
if(block.inputs[input].joined in cache){ //if output of other block is already in cache
inputValues[input] = cache[block.inputs[input].joined];
}
else{
var inputBlock = diagram.state.filter((diagramBlock)=>(diagramBlock.id == block.inputs[input].joined))[0]; //find block instance
inputValues[input] = resolveOutput(inputBlock, cache); //calculate and store output
}
} }
else{ else if(block.inputs[input].value){ //if value is already set, just save that
var inputBlock = diagram.state.filter((diagramBlock)=>(diagramBlock.id == block.inputs[input].joined))[0]; //find block instance inputValues[input] = block.inputs[input].value;
inputValues[input] = resolveOutput(inputBlock, cache); //calculate and store output }
if(blocks[block.type].inputs[input].required && !(inputValues[input])){ //if input is required and is missing
throw "A required input is missing";
} }
} }
else if(block.inputs[input].value){ //if value is already set, just save that
inputValues[input] = block.inputs[input].value; var output = blocks[block.type].execute(inputValues, block);
} cache[block.id] = output;
return output;
}
catch(err){
console.log("ERROR", err);
return "";
} }
var output = blocks[block.type].execute(inputValues, block);
cache[block.id] = output;
return output;
} }
function calculateOutputBlocks(){ function calculateOutputBlocks(){