Skip to content

fix: prevent panic when local commands omit required arguments - #266

Open
Bewear777 wants to merge 2 commits into
vesoft-inc:masterfrom
Bewear777:fix/local-command-missing-arguments
Open

Bewear777 wants to merge 2 commits into
vesoft-inc:masterfrom
Bewear777:fix/local-command-missing-arguments

Conversation

@Bewear777

@Bewear777 Bewear777 commented Nov 2, 2026 •

Copy link
Copy Markdown

What type of PR is this?

  • bug
  • feature
  • enhancement

What problem(s) does this PR solve?

Issue(s) number:

Fixes #263

Related: #162, #236

Description:

  • Check for an empty local command before accessing words[0].
  • Validate required arguments for local commands before accessing words[1].
  • Return parsing errors from isConsoleCmd().
  • Let loop() display errors and continue the interactive session.
  • Preserve existing handling of unknown local commands.
  • Preserve commands that do not require arguments, such as :params.
  • Add unit tests for missing arguments and normal command behavior.

How to reproduce:

Start NebulaGraph Console in interactive mode using a build that does not contain this fix.

Execute each command below separately. Each command should be tested in a fresh Console process because the original panic terminates the current process.

1. Empty local command

:

Previously, this caused:

panic: runtime error: index out of range [0] with length 0

The parser accesses words[0] even though the command contains no command name.

2. Local commands with missing required arguments

Run each of the following commands separately:

:sleep
:play
:repeat
:csv
:dot
:profile
:explain

Previously, each command caused:

panic: runtime error: index out of range [1] with length 1

The corresponding command handlers access words[1] without first checking whether the required argument exists.

Expected behavior:

  • Entering : displays a clear empty-command error instead of panicking.
  • Entering any of the seven commands without its required argument displays a clear missing-argument error.
  • Console remains running and accepts the next command.
  • Valid local commands and unknown-command handling remain unchanged.

How to verify:

1. Run the targeted unit test for all missing-argument cases:

go test -count=1 -run '^TestIsConsoleCmdMissingRequiredArguments$' -v .

This test covers all eight inputs: :, :sleep, :play, :repeat, :csv, :dot, :profile, and :explain.

2. Run all local-command unit tests:

go test -count=1 -run '^TestIsConsoleCmd' -v .

This also verifies:

  • :repeat 3 is parsed successfully with its argument.
  • An unknown local command does not produce a parsing error.
  • :params continues to work without an argument.

3. Run all repository tests:

go test -count=1 ./...

4. Verify interactively:

In a Console build containing this fix, enter each of the eight reproduction commands separately. Verify that Console displays an error and continues accepting input instead of exiting.

Then verify normal behavior with:

:repeat 1
:params
:unknown

The first two commands should retain their existing behavior, and the unknown command should continue to be handled by the existing unknown-command path.

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.

Local commands without required arguments cause runtime panic

1 participant