}
});
+function abort(error: Error) {
+ console.error(error);
+ Deno.exit(1);
+}
+
+// Validate and process words argument
const dictionary: string[] = [];
-await Deno.readTextFile(words).then(f => dictionary.push(...f.split(/\r?\n/)));
+await Deno.readTextFile(words)
+ .then(f => dictionary.push(...f.split(/\r?\n/)))
+ .catch(abort); // Will throw if an invalid file path is given
-const rand = new Uint16Array(parseInt(length));
+// Validate and process length argument
+const len = parseInt(length);
+if (isNaN(len)) {
+ abort(new TypeError(`${length} is not a number.`));
+}
+const rand = new Uint16Array(len);
crypto.getRandomValues(rand);
const output: string[] = [];