Skip to content

fix: don't panic on :connect without a server name - #845

Open
Hitarth Jain (Yeagerist0) wants to merge 1 commit into
microsoft:mainfrom
Yeagerist0:fix/connect-without-server
Open

Hitarth Jain (Yeagerist0) wants to merge 1 commit into
microsoft:mainfrom
Yeagerist0:fix/connect-without-server

Conversation

@Yeagerist0

Copy link
Copy Markdown

Typing :connect with no server name panics:

panic: runtime error: slice bounds out of range [1:0]

The CONNECT regex yields one empty argument for a bare :connect, so the len(args) == 0 check passes, strings.Fields returns an empty slice and commandArgs[1:] panics. The existing test passes []string{}, which the parser never produces here.

The fix returns the usual invalid-command error. The new test goes through matchCommand; its :connect and :CONNECT cases panic on main. commands.go keeps its CRLF line endings.

Testing: the new test, go build ./... and go vet ./pkg/sqlcmd pass. I did not run the tests that need a SQL Server instance.

AI disclosure: Claude Code found the bug and wrote the fix, test and this description; the results above are from local runs.

The command regex yields one empty argument for a bare :connect, so
strings.Fields returns nothing and commandArgs[1:] panics.
Copilot AI balanced review requested due to automatic review settings December 5, 2026 12:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change to handle :connect commands without a server name.

No open issues 🎉

What changed in this PR

Prevents sqlcmd from panicking when :connect is entered without a server name, returning the standard invalid-command error instead.

Changes:

  • Reject empty parsed arguments before accessing the server name.
  • Add parser-based regression tests for bare, whitespace-only, and comment-only :connect commands.
File Description
pkg/​sqlcmd/​connect_command_test.go Adds regression tests for missing server names.
pkg/​sqlcmd/​commands.go Guards empty arguments and removes a redundant check.

Review effort: Balanced

@Yeagerist0

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

2 participants