Skip to content
Snippets Groups Projects
Commit 7bc534e9 authored by Stuffed's avatar Stuffed
Browse files

<<options>> Show a more friendly error if we're missing the variable

parent 5fbe352f
No related branches found
No related tags found
1 merge request!3981Pregmod master
...@@ -31,12 +31,13 @@ Macro.add('options', { ...@@ -31,12 +31,13 @@ Macro.add('options', {
var comment = null; var comment = null;
var hasMultipleOptionsWithSameValue = false; var hasMultipleOptionsWithSameValue = false;
var description = ""; 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 /* Check if we have a first argument - if we do, it should be a
variable like $foo variable like $foo
*/ */
if (this.payload[0].args.full && if (hasCurrentOption) {
this.payload[0].args.full !== '""' && this.payload[0].args.full !== "''") {
if (currentOption === undefined) if (currentOption === undefined)
currentOption = false; currentOption = false;
if (this.payload[0].args.full.startsWith("State.temporary.")) { if (this.payload[0].args.full.startsWith("State.temporary.")) {
...@@ -95,6 +96,21 @@ Macro.add('options', { ...@@ -95,6 +96,21 @@ Macro.add('options', {
throw new Error("Only valid tag is 'option' inside '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; var showSelectedOption = true; //this.payload.length !== 3 || !description;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment