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

View File

@ -3,7 +3,9 @@ var events = require("./events.js");
var blocks = require("./blocks");
function resolveOutput(block, cache){
try{
var inputValues = {};
var error = "";
for(var input in block.inputs){
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
@ -17,12 +19,19 @@ function resolveOutput(block, cache){
else if(block.inputs[input].value){ //if value is already set, just save that
inputValues[input] = block.inputs[input].value;
}
if(blocks[block.type].inputs[input].required && !(inputValues[input])){ //if input is required and is missing
throw "A required input is missing";
}
}
var output = blocks[block.type].execute(inputValues, block);
cache[block.id] = output;
return output;
}
catch(err){
console.log("ERROR", err);
return "";
}
}
function calculateOutputBlocks(){