Skip to content

Commit 56611ce

Browse files
fix(open): fail fast on 'open vscode' and 'open ssms' with no current context
Without a current context, both commands would call config.CurrentContext() (returning zero-value endpoint/user) and proceed to write an empty profile or launch with an empty host. Match start/stop/uninstall by exiting with 'No current context' and a hint to 'sqlcmd config get-contexts'.
1 parent 99a29a5 commit 56611ce

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

cmd/modern/root/open/ssms_run_windows.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ const minSsmsVersion = 21
2525
func (c *SSMS) run() {
2626
c.validateVersion()
2727

28+
if config.CurrentContextName() == "" {
29+
c.Output().FatalWithHintExamples([][]string{
30+
{localizer.Sprintf("To view available contexts"), "sqlcmd config get-contexts"},
31+
}, localizer.Sprintf("No current context"))
32+
}
33+
2834
endpoint, user := config.CurrentContext()
2935
isLocalConnection := isLocalEndpoint(endpoint)
3036

cmd/modern/root/open/vscode.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ func (c *VSCode) DefineCommand(...cmdparser.CommandOptions) {
5959
// The connection profile will be added to VS Code's user settings to work
6060
// with the MSSQL extension.
6161
func (c *VSCode) run() {
62+
if config.CurrentContextName() == "" {
63+
c.Output().FatalWithHintExamples([][]string{
64+
{localizer.Sprintf("To view available contexts"), "sqlcmd config get-contexts"},
65+
}, localizer.Sprintf("No current context"))
66+
}
67+
6268
endpoint, user := config.CurrentContext()
6369

6470
build := c.resolveBuild()

0 commit comments

Comments
 (0)