Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

samirsilwal
Copy link
Collaborator

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
image

After

DEBUG=* yarn sync-db gg

image

@samirsilwal samirsilwal self-assigned this Oct 26, 2024
@samirsilwal
Copy link
Collaborator Author

Resolves #242

@samirsilwal samirsilwal added bug Something isn't working bugfix and removed bug Something isn't working labels Oct 26, 2024
Copy link

codecov bot commented Oct 26, 2024

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 35.13%. Comparing base (8322436) to head (c9a1cfb).

Files with missing lines Patch % Lines
src/commands/index.ts 0.00% 5 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@samirsilwal
Copy link
Collaborator Author

Will add the tests

@anishmanandhar anishmanandhar requested a review from Copilot May 29, 2025 08:21
Copy link

@Copilot Copilot AI left a 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 = [

Comment on lines +19 to +20
// and if the command is not in the list of available commands
if (process.argv.length >= 3 && !availableCommands.includes(process.argv[2])) {
Copy link
Preview

Copilot AI May 29, 2025

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.

Suggested change
// 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant