microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
337 stars 59 forks source link

context without user causes error :) #246

Closed bweissman closed 1 year ago

bweissman commented 1 year ago

if I don't provide a user for my context (SQL auth), the error message isn't very intuitive :)

.\sqlcmd config add-endpoint --name test --address 192.168.100.100 .\sqlcmd config add-context --name test --endpoint test .\sqlcmd config connection-strings panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x0 pc=0x5b45be]

goroutine 1 [running]: github.com/microsoft/go-sqlcmd/internal/config.CurrentContext() D:/a/1/s/internal/config/context.go:79 +0x2be github.com/microsoft/go-sqlcmd/cmd/modern/root/config.(ConnectionStrings).run(0x0?) D:/a/1/s/cmd/modern/root/config/connection-strings.go:51 +0x136 github.com/microsoft/go-sqlcmd/internal/cmdparser.(Cmd).run(0xc000404a80, 0x0?, {0x1178c30?, 0x0?, 0x0?}) D:/a/1/s/internal/cmdparser/cmd.go:286 +0x256 github.com/spf13/cobra.(Command).execute(0xc000404b20, {0x1178c30, 0x0, 0x0}) C:/Users/VssAdministrator/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:920 +0x847 github.com/spf13/cobra.(Command).ExecuteC(0xc000100ca0) C:/Users/VssAdministrator/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:1044 +0x3bc github.com/spf13/cobra.(Command).Execute(...) C:/Users/VssAdministrator/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:968 github.com/microsoft/go-sqlcmd/internal/cmdparser.(Cmd).Execute(0xc000100c00) D:/a/1/s/internal/cmdparser/cmd.go:154 +0x2a main.(*Root).Execute(...) D:/a/1/s/cmd/modern/root.go:80 main.main() D:/a/1/s/cmd/modern/main.go:46 +0x205

if however I add the user:

.\sqlcmd config add-user --name test --username demo .\sqlcmd config add-endpoint --name test --address 192.168.100.100 .\sqlcmd config add-context --name test --endpoint test --user test .\sqlcmd config connection-strings

everything works fine

stuartpa commented 1 year ago

My mistake (we recently changed this to an optional value)