Handle the invalid command resulting in infinite loop#243
Open
samirsilwal wants to merge 1 commit intomasterfrom
Open
Handle the invalid command resulting in infinite loop#243samirsilwal wants to merge 1 commit intomasterfrom
samirsilwal wants to merge 1 commit intomasterfrom
Conversation
Collaborator
Author
|
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. |
Collaborator
Author
|
Will add the tests |
There was a problem hiding this comment.
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
availableCommandsinto a shared constant or configuration module to avoid duplication and ease future maintenance.
const availableCommands = [
Member
|
@samirsilwal Surprised that ocli doesn't have this by default? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ggAfter
DEBUG=* yarn sync-db gg