Skip to content

go usage and help messages write to stderr instead of stdout #17284

@fschr

Description

@fschr

Version

go 1.7 darwin/amd64

OS + Architecture

GOARCH="amd64"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did I do?

go --help and go [subcommand] --help

What did you expect to see?

I expected these commands to write to stdout. I was trying to see what the -i flag in go build -i does, so I ran the command go build --help | grep -- -i.

What did you see instead?

My buffer was flooded with the entire go build --help message because it writes to stderr instead of stdout. This means I have to run go {subcommand} --help 2>&1 | grep -- -{flag} when figuring out what a flag does.

However, when running commands like go env and go version, output is written to stdout. This leads to confusion: when should I have to combine stderr and stdout? What if there was a genuine error in the go {subcommand} that I run? I don't want to pipe that through grep and miss it, it may be important.

I think go should pick a file descriptor---either stdout or stderr---to write all go output to. In my opinion, go should only ever write to stderr if the binary itself fails in some respect. That way I don't miss any errors because I'm piping all of stderr through grep, head, and the like.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions