Skip to content

Commit

Permalink
Better error message when value missing after operator
Browse files Browse the repository at this point in the history
  • Loading branch information
dfabulich committed Nov 7, 2017
1 parent a17dee2 commit 7c0a4a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/scenetest.js
Expand Up @@ -1141,6 +1141,13 @@ test("errorMissingOperator", function() {
doh.is([{"value":"3","name":"NUMBER","pos":1},{"value":"3","name":"NUMBER","pos":3}], stack, "stack");
doh.assertError(Error, scene, "evaluateExpr", stack, "Invalid expression");
})
test("errorMissingValueAfterOperator", function() {
var scene = new Scene();
var stack = scene.tokenizeExpr("3 =");
//print(toJson(stack))
doh.is([{"name":"NUMBER","value":"3","pos":1},{"name":"EQUALITY","value":"=","pos":3}], stack, "stack");
doh.assertError(Error, scene, "evaluateExpr", stack, "Invalid expression");
})
test("errorEmptyStack", function() {
var scene = new Scene();
doh.assertError(Error, scene, "evaluateExpr", [], "Invalid expression");
Expand Down
4 changes: 4 additions & 0 deletions web/scene.js
Expand Up @@ -3473,6 +3473,10 @@ Scene.prototype.evaluateExpr = function evaluateExpr(stack, parenthetical) {
this.warning("For more details on modulo, see: https://forum.choiceofgames.com/t/21176");
}

if (!stack[0]) {
throw new Error(this.lineMsg() + "Invalid expression at char "+token.pos+", expected something after a "+token.value);
}

if (stack[0].func == "auto") {
value2 = this.autobalance(stack, token, value1);
} else {
Expand Down

0 comments on commit 7c0a4a6

Please sign in to comment.