From 7bc534e9becf3023e26747b464088d42d8799f94 Mon Sep 17 00:00:00 2001
From: StuffedAnon <stuffedgame@gmail.com>
Date: Wed, 20 Mar 2019 08:33:20 +0900
Subject: [PATCH] <<options>> Show a more friendly error if we're missing the
 variable

---
 src/js/optionsMacro.js | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/js/optionsMacro.js b/src/js/optionsMacro.js
index 3e089e5815a..b4d81c6d548 100644
--- a/src/js/optionsMacro.js
+++ b/src/js/optionsMacro.js
@@ -31,12 +31,13 @@ Macro.add('options', {
 			var comment = null;
 			var hasMultipleOptionsWithSameValue = false;
 			var description = "";
+			var hasCurrentOption = this.payload[0].args.full &&
+			this.payload[0].args.full !== '""' && this.payload[0].args.full !== "''";
 
 			/* Check if we have a first argument - if we do, it should be a
 			   variable like $foo
 			  */
-			if (this.payload[0].args.full &&
-					this.payload[0].args.full !== '""' && this.payload[0].args.full !== "''") {
+			if (hasCurrentOption) {
 				if (currentOption === undefined)
 					currentOption = false;
 				if (this.payload[0].args.full.startsWith("State.temporary.")) {
@@ -95,6 +96,21 @@ Macro.add('options', {
 						throw new Error("Only valid tag is 'option' inside 'options'");
 					}
 				}
+			} else {
+				// No variable was passed to <<options>>
+				// This is valid, but then we only allow an empty <<option>> or <<comment>>
+				// inside
+				for (let i = 1, len = this.payload.length; i < len; ++i) {
+					if (this.payload[i].name === 'option' && this.payload[i].args.length === 0) {
+						// This is valid for an empty <<options>>
+					} else if (this.payload[i].name === "comment") {
+						// This is valid for an empty <<options>>
+					} else {
+						throw new Error("Missing variable to <<options>>");
+					}
+
+				}
+
 			}
 
 			var showSelectedOption = true; //this.payload.length !== 3 || !description;
-- 
GitLab