diff --git a/.changeset/fix-undefined-error-in-fail-callback.md b/.changeset/fix-undefined-error-in-fail-callback.md new file mode 100644 index 00000000..f0745e34 --- /dev/null +++ b/.changeset/fix-undefined-error-in-fail-callback.md @@ -0,0 +1,5 @@ +--- +"@smartthings/cli": patch +--- + +Fix TypeError crash when running `smartthings` or `smartthings -h` without a subcommand. Yargs passes `undefined` as the error argument to the `.fail()` callback for validation failures; the `in` operator threw when the operand was `undefined`. diff --git a/src/index.ts b/src/index.ts index 3f6f8708..cec45ce4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,7 +32,7 @@ export const buildInstance = (commands: CommandModule[]): Argv => { /* eslint-enable @typescript-eslint/naming-convention */ .completion('generate-completions-script', 'output completion script setup') .fail((message, error, yargs) => { - if ('isAxiosError' in error && error.isAxiosError) { + if (error && 'isAxiosError' in error && error.isAxiosError) { // We don't print axiosError.message here because it just duplicates the things // we're displaying but unformatted. const axiosError = error as AxiosError