From 33c7689d9f9435ef21628f5af0029b741a12fa48 Mon Sep 17 00:00:00 2001 From: Sebastian-Webster <84299475+Sebastian-Webster@users.noreply.github.com> Date: Wed, 15 Jan 2025 01:24:20 +0400 Subject: [PATCH 1/2] gracefully fail if invalid option is passed to cli --- src/cli.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cli.ts b/src/cli.ts index 3e807cf3..c4a67a40 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node import { createDB } from "./index"; -import { OPTION_TYPE_CHECKS } from "./constants"; +import { DEFAULT_OPTIONS_KEYS, OPTION_TYPE_CHECKS } from "./constants"; import { ServerOptions } from "../types"; async function main() { @@ -9,6 +9,10 @@ async function main() { _DO_NOT_USE_cli: true } for (const opt of definedOptions) { + if (!DEFAULT_OPTIONS_KEYS.includes(opt)) { + throw `Option ${opt} is not a valid option.` + } + const index = process.argv.indexOf(opt) const optionValue = process.argv[index + 1] From 0b6f59771f0f9c8604972d3c5f6568eb18ecffd2 Mon Sep 17 00:00:00 2001 From: Sebastian-Webster <84299475+Sebastian-Webster@users.noreply.github.com> Date: Wed, 15 Jan 2025 01:28:10 +0400 Subject: [PATCH 2/2] change throws to console.error in cli --- src/cli.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index c4a67a40..318bc3a2 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -10,14 +10,16 @@ async function main() { } for (const opt of definedOptions) { if (!DEFAULT_OPTIONS_KEYS.includes(opt)) { - throw `Option ${opt} is not a valid option.` + console.error(`Option ${opt} is not a valid option.`) + return } const index = process.argv.indexOf(opt) const optionValue = process.argv[index + 1] if (optionValue === undefined) { - throw `Option ${opt} must have a value.` + console.error(`Option ${opt} must have a value.`) + return } const optionName = opt.slice(2)