-
Notifications
You must be signed in to change notification settings - Fork 15
Handle the invalid command resulting in infinite loop #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Resolves #242 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #243 +/- ##
==========================================
- Coverage 35.34% 35.13% -0.21%
==========================================
Files 33 34 +1
Lines 863 868 +5
Branches 115 116 +1
==========================================
Hits 305 305
- Misses 549 554 +5
Partials 9 9 ☔ View full report in Codecov by Sentry. |
Will add the tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds validation for CLI commands in sync-db
to prevent infinite loops by exiting when an unrecognized command is provided.
- Defines a list of supported commands and checks
process.argv[2]
against it. - Prints an error message and exits with code 1 if the command is invalid.
Comments suppressed due to low confidence (3)
src/commands/index.ts:20
- There are no tests covering the invalid command handling path; consider adding a test to verify that an unrecognized command triggers the correct error message and exit code.
if (process.argv.length >= 3 && !availableCommands.includes(process.argv[2])) {
src/commands/index.ts:21
- [nitpick] The error message lists all commands in a single line, which can be hard to scan; consider formatting them as a multi-line list or table for better readability.
await printError(`Invalid command. Please use one of the following commands: ${availableCommands.join(', ')}`);
src/commands/index.ts:6
- [nitpick] The list of commands may need to be updated elsewhere in the codebase; consider extracting
availableCommands
into a shared constant or configuration module to avoid duplication and ease future maintenance.
const availableCommands = [
// and if the command is not in the list of available commands | ||
if (process.argv.length >= 3 && !availableCommands.includes(process.argv[2])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Destructure process.argv
(e.g., const [, , command] = process.argv
) for improved readability when extracting the command argument.
// and if the command is not in the list of available commands | |
if (process.argv.length >= 3 && !availableCommands.includes(process.argv[2])) { | |
const [, , command] = process.argv; | |
// and if the command is not in the list of available commands | |
if (process.argv.length >= 3 && !availableCommands.includes(command)) { |
Copilot uses AI. Check for mistakes.
Changes
Check if the command provided to sync-db in valid one
Show the available command in case of invalid entry
Fixes the infinite loop while unknown command is given to sync-db
Test
Before
DEBUG=* yarn sync-db gg
After
DEBUG=* yarn sync-db gg