Improve error handling and error readability for all commands#1614
Improve error handling and error readability for all commands#1614ivanvpetrov wants to merge 3 commits intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves ig CLI UX by replacing stack traces and unintended interactive fallbacks with clearer error messages, help output, and a catch-all async error handler at the entry point.
Changes:
- Add a yargs
.fail()handler to surface validation errors cleanly and show help. - Treat unknown commands as errors (with help) and only enter interactive mode when invoked with no args.
- Catch unexpected async errors in the CLI entry point and exit with failure.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
packages/cli/lib/cli.ts |
Adds yargs failure handling and differentiates unknown-command vs no-args interactive fallback. |
packages/cli/bin/execute.js |
Wraps cli.run() with a .catch() to avoid unhandled rejection crashes and exit non-zero. |
spec/unit/cli-spec.ts |
Updates/extends unit coverage for no-args fallback, unknown command error, and validation failures. |
CHANGELOG.md |
Documents the CLI error-handling fixes and behavior changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…rrors Agent-Logs-Url: https://github.com/IgniteUI/igniteui-cli/sessions/9e5da6c9-348d-43b7-8bc9-e0b558ebbab3 Co-authored-by: ivanvpetrov <110455887+ivanvpetrov@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Closes #1610
Closes #1612
fix(cli): improve error handling and error readability for all commands
Summary
This PR improves the error handling and user-facing error messages across all
igCLI commands. Previously, certain invalid inputs would either crash with a raw Node.js stack trace or silently fall through to interactive mode — both confusing for the user.Changes
Error handling for command validation failures
Added a
.fail()handler to the yargs instance incli.ts. When a command fails its own validation (e.g.ig generatewithout providing a required subcommand), yargs previously threw an unhandled exception resulting in a stack trace. Now the user sees a clear error message and the relevant help output.Before:
P.n.fail ... Object.nonOptionCount ... (stack trace)After:
Please select commandCommands:generate template [name] generates custom templateUnknown command detection
Running
ig <unknown>previously silently dropped into the step-by-step interactive mode as if no command was provided. The interactive mode now only activates when the user runsigwith no arguments at all — the intentional entry point. Providing an unrecognized command now gives explicit feedback.Before:
Starting Step by step mode...? Enter a name for your project:After:
Unknown command: "asdf"(+ help listing all available commands)Unhandled promise rejection in entry point
Added a
.catch()on thecli.run()call inexecute.jsso that any unexpected async errors produce a cleanError: <message>output instead of a Node.js unhandled rejection crash.Tests
Updated and extended
spec/unit/cli-spec.ts:"Should fire properly - fallback to default"— now explicitly passes empty args to confirm step-by-step mode is only triggered with no input"Should show error for unknown command"— verifiesUtil.erroris called with the unknown command name and the prompt session is not started"Should gracefully handle subcommand validation errors"— verifies the.fail()handler surfaces the yargsdemandCommandmessage instead of crashing