Skip to content

fix: guard against undefined error in yargs fail callback#835

Open
monitoring-smartthings wants to merge 2 commits into
SmartThingsCommunity:mainfrom
monitoring-smartthings:fix/fail-callback-undefined-error
Open

fix: guard against undefined error in yargs fail callback#835
monitoring-smartthings wants to merge 2 commits into
SmartThingsCommunity:mainfrom
monitoring-smartthings:fix/fail-callback-undefined-error

Conversation

@monitoring-smartthings
Copy link
Copy Markdown

Summary

Running smartthings or smartthings -h without a subcommand crashes with a TypeError instead of showing usage help:

file:///opt/homebrew/lib/node_modules/@smartthings/cli/dist/src/index.js:30
        if ('isAxiosError' in error && error.isAxiosError) {
                           ^

TypeError: Cannot use 'in' operator to search for 'isAxiosError' in undefined

Yargs calls the .fail() callback with (message, undefined, yargs) when a validation failure is not caused by a thrown error (e.g. no subcommand provided, triggering .demandCommand()). The in operator throws a TypeError when its right-hand operand is undefined.

Fix: add a null-guard (error &&) before the in check so undefined falls through to the else branch, which correctly prints the yargs-generated message and help text.

Test plan

  • Run smartthings with no arguments — should print usage/help instead of crashing
  • Run smartthings -h — should print help instead of crashing
  • Run a command that triggers an Axios error — should still display the API error message correctly
  • Run a command that throws a non-Axios error — should still display error.message

🤖 Generated with Claude Code

Running `smartthings` or `smartthings -h` without a subcommand crashed
with a TypeError instead of showing usage help.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 13, 2026

🦋 Changeset detected

Latest commit: 5c9021f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@smartthings/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant