-r discards the "Msg N, Level N, State N" error header — errors on stderr lose message number and line info
还没有人认领这个 Issue。
- #811 来自 @Raymondriter —— 已关闭,未合并
评估
调研方向
从 cmd/sqlcmd/sqlcmd.go 中的 -r PrintError hook 开始,然后阅读 pkg/sqlcmd/format.go 中的 Formatter.AddError,以比较现有的 header 格式。重现 issue 中的命令,并验证 -r 会将相同的 Msg、Level、State、Server 和 Line header 以及消息发送到 stderr,同时保留现有的目标行为。
由索引模型根据 Issue 内容生成。
描述
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)
- 主要语言
- Go
- 星标
- 604
- 派生
- 91
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/go-sqlcmd 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 3/5 1-2 天 新手友好度 55/100
-
难度 3/5 1-2 天 新手友好度 65/100
-
Go + tab is not understood.可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 3/5 1-2 天 新手友好度 58/100
查看 microsoft/go-sqlcmd 的全部 Issue
相似的 Issue
-
bug go
难度 2/5 1-3 小时 新手友好度 82/100
genkit-ai/genkit#6761 · 1 条评论 ·
维护者通常 2 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 87/100
维护者通常 2 天内回复
-
ready
难度 2/5 1-3 小时 新手友好度 92/100
kubeflow/pipelines#14784 · 1 条评论 ·
维护者通常 2 天内回复
-
bug frontend good first issue
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
trust: update-propagation-directive requires developer mode while add and remove do not可能已有人在做 @bhuvan-somisetty 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复