-r discards the "Msg N, Level N, State N" error header — errors on stderr lose message number and line info
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 76/100
Línea de trabajo
Comienza en cmd/sqlcmd/sqlcmd.go, en el hook PrintError de -r, y luego lee Formatter.AddError en pkg/sqlcmd/format.go para comparar el formato de header existente. Reproduce los comandos del issue y verifica que -r envíe el mismo header Msg, Level, State, Server y Line, además del mensaje, a stderr, preservando el comportamiento de destino existente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
When -r (errors to stderr) is specified, server error messages are written to stderr
as bare message text only — the Msg %d, Level %d, State %d, Server %s, Line %d
header line is silently dropped. Without -r, the header prints correctly (to stdout).
ODBC sqlcmd with -r prints the same formatted output (header + message), just
redirected to stderr. So scripts/CI pipelines migrating from ODBC sqlcmd lose the error
number and line information exactly in the configuration meant for error capture.
Repro
-- repro.sql
SELECT id, badColumn FROM sys.objects WHERE object_id = 1;
GO
> sqlcmd -S myserver -E -b -i repro.sql # no -r
Msg 207, Level 16, State 1, Server MYSERVER, Line 1
Invalid column name 'id'.
> sqlcmd -S myserver -E -r -b -i repro.sql # with -r
Invalid column name 'id.' <-- stderr: message text only, no Msg/Level/State/Line
ODBC sqlcmd (16.0.1000.6) with the identical -r -b flags writes to stderr:
Msg 207, Level 16, State 1, Server MYSERVER, Line 1
Invalid column name 'id'.
Msg 207, Level 16, State 1, Server MYSERVER, Line 1
Invalid column name 'badColumn'.
Root cause (from source)
Formatter.AddError in pkg/sqlcmd/format.go formats the header correctly for
mssql.Error. But when -r is passed, cmd/sqlcmd/sqlcmd.go installs a
s.PrintError hook that receives only e.Message and writes it directly to
os.Stderr, returning true — which bypasses Format.AddError entirely:
s.PrintError = func(msg string, severity uint8) bool {
if severity >= stderrSeverity {
s.WriteError(os.Stderr, errors.New(msg+sqlcmd.SqlcmdEol))
return true
}
return false
}
Suggested fix: format the full header inside the hook (or route through the formatter
with a stderr destination) so -r only changes the destination, not the format —
matching ODBC sqlcmd behavior.
Additional observation
Combined with -b, only the first error of a batch is reported (the message loop
exits on the first qualifying error), while ODBC sqlcmd prints all errors of the
response before exiting. Together with the missing header this significantly degrades
error diagnostics for deployment scripts.
Environment
- sqlcmd v1.10.0 (sqlcmd-windows-amd64.zip from Releases)
- Windows 11, SQL Server 2022 (16.0.1190.2)
- Compared against ODBC sqlcmd 16.0.1000.6 with identical flags
- (Server messages in our environment are localized/Korean; behavior is language-independent)
- Lenguaje dominante
- Go
- Estrellas
- 595
- Forks
- 91
- Merge medio
- 9 h 35 min
- PR fusionados (30 d)
- 1
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/go-sqlcmd
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Fix CVEs in Version v1.10.0 Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
-
":Help" command not working Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
-
Go + tab is not understood. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 58/100
Todos los issues de microsoft/go-sqlcmd
Issues similares
-
bug github_actions
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
registrystack/registry-stack#1393 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
JakeChampion/lang#10213 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
oasisprotocol/oasis-sdk#2523 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100