diff --git a/common/content/dactyl.js b/common/content/dactyl.js index b8c95ef4..916dd18e 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -1183,7 +1183,8 @@ const Dactyl = Module("dactyl", { options.safeSetPref("layout.scrollbar.side", opts.indexOf("l") >= 0 ? 3 : 2, "See 'guioptions' scrollbar flags."); }, - validator: function (opts) (opts.indexOf("l") < 0 || opts.indexOf("r") < 0) + validator: function (opts) Option.validIf(!(opts.indexOf("l") >= 0 && opts.indexOf("r") >= 0), + UTF8("Only one of ‘l’ or ‘r’ allowed")) }, tab: { feature: "tabs", @@ -1271,7 +1272,7 @@ const Dactyl = Module("dactyl", { options.add(["verbose", "vbs"], "Define which info messages are displayed", "number", 1, - { validator: function (value) value >= 0 && value <= 15 }); + { validator: function (value) Option.validIf(value >= 0 && value <= 15, "Value must be between 0 and 15") }); options.add(["visualbell", "vb"], "Use visual bell instead of beeping on errors", diff --git a/common/content/hints.js b/common/content/hints.js index 6fb546c6..b1d91a98 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -1072,7 +1072,8 @@ const Hints = Module("hints", { ["asdfg;lkjh", "Home Row"]], validator: function (value) { let values = events.fromString(value).map(events.closure.toString); - return array.uniq(values).length === values.length; + return Option.validIf(array.uniq(values).length === values.length, + "Duplicate keys not allowed") } }); diff --git a/common/content/options.js b/common/content/options.js index 63613df5..01a4f869 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -234,8 +234,13 @@ const Option = Class("Option", { if (newValues == null) return "Operator " + operator + " not supported for option type " + this.type; - if (!this.isValidValue(newValues)) - return this.invalidArgument(str || this.joinValues(values), operator); + try { + if (!this.isValidValue(newValues)) + return this.invalidArgument(str || this.joinValues(values), operator); + } + catch (e) { + return this.invalidArgument(str || this.joinValues(values), operator) + ": " + e.message; + } this.setValues(newValues, scope); return null; @@ -551,6 +556,12 @@ const Option = Class("Option", { } }, + validIf: function (test, error) { + if (test) + return true; + throw Error(error); + }, + // TODO: Run this by default? /** * Validates the specified values against values generated by the