Browse Source

EAGLESIX-2699 Add error codes to error messages. Add test cases for missing arguments.

Tony Ennis 11 years ago
parent
commit
187808cacf

+ 3 - 3
lib/pipeline/expressions/CondExpression.js

@@ -81,9 +81,9 @@ klass.parse = function parse(expr, vps) {
 		}
 	});
 
-    if (!ret.operands[0]) throw new Error("Missing 'if' parameter to $cond");
-    if (!ret.operands[1]) throw new Error("Missing 'then' parameter to $cond");
-    if (!ret.operands[2]) throw new Error("Missing 'else' parameter to $cond");
+    if (!ret.operands[0]) throw new Error("Missing 'if' parameter to $cond; code 17080");
+    if (!ret.operands[1]) throw new Error("Missing 'then' parameter to $cond; code 17081");
+    if (!ret.operands[2]) throw new Error("Missing 'else' parameter to $cond; code 17082");
 
     return ret;
 };

+ 24 - 0
test/lib/pipeline/expressions/CondExpression_test.js

@@ -50,6 +50,21 @@ module.exports = {
 
 				"should evaluate boolean expression as false, then return 0; [ false === true, 1, 0 ]": function () {
 					assert.strictEqual(Expression.parseOperand({$cond: [ false, 1, 0 ]}, {}).evaluateInternal({}), 0);
+				},
+				"should fail when the 'if' position is empty": function(){
+					assert.throws(function(){
+						Expression.parseOperand({$cond:[undefined, 2, 3]}, {});
+					})
+				},
+				"should fail when the 'then' position is empty": function(){
+					assert.throws(function(){
+						Expression.parseOperand({$cond:[1, undefined, 3]}, {});
+					})
+				},
+				"should fail when the 'else' position is empty": function(){
+					assert.throws(function(){
+						Expression.parseOperand({$cond:[1, 2, undefined]}, {});
+					})
 				}
 			},
 
@@ -73,6 +88,15 @@ module.exports = {
 				"should fail because of missing else": function(){
 					this.shouldFail({$cond:{if:1, then:2, xelse:3}});
 				},
+				"should fail because of empty if": function(){
+					this.shouldFail({$cond:{if:undefined, then:2, else:3}});
+				},
+				"should fail because of empty then": function(){
+					this.shouldFail({$cond:{if:1, then:undefined, else:3}});
+				},
+				"should fail because of empty else": function(){
+					this.shouldFail({$cond:{if:1, then:2, else:undefined}});
+				},
 				"should fail because of mystery args": function(){
 					this.shouldFail({$cond:{if:1, then:2, else:3, zoot:4}});
 				},