-r discards the "Msg N, Level N, State N" error header — errors on stderr lose message number and line info
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 76/100
Direzione di ricerca
Inizia in cmd/sqlcmd/sqlcmd.go all’hook PrintError di -r, quindi leggi Formatter.AddError in pkg/sqlcmd/format.go per confrontare la formattazione dell’header esistente. Riproduci i comandi dell’issue e verifica che -r invii a stderr lo stesso header Msg, Level, State, Server e Line insieme al messaggio, preservando il comportamento di destinazione esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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)
- Lingua principale
- Go
- Stelle
- 595
- Fork
- 91
- Merge medio
- 9h 35m
- PR unite (30g)
- 1
Preparare l'ambiente
Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/go-sqlcmd
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Fix CVEs in Version v1.10.0Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
microsoft/go-sqlcmd#733 · 7 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
-
":Help" command not workingAperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Go + tab is not understood.Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/go-sqlcmd
Issue simili
-
Remove CAAPFApertakind/chore kind/cleanup needs-area
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
rancher/turtles#2848 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
priority: low 🌱 type: enhancement 💅🏼
Difficoltà 2/5 Mezza giornata Idoneità per principianti 84/100
nebari-dev/llm-serving-pack#199 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
kedacore/keda#8225 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno