From: Brad Fitzpatrick Date: Thu, 9 May 2019 21:04:39 +0000 (+0000) Subject: os/user: make Current return better error w/o cgo & complete environment X-Git-Tag: go1.13beta1~343 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b8d5150f4a81c82ae7ebeb750f568055b7e8b212;p=gostls13.git os/user: make Current return better error w/o cgo & complete environment Fixes #31949 Change-Id: Ib96a43e4c56a00c5ba04e4d213255a063058ae08 Reviewed-on: https://go-review.googlesource.com/c/go/+/176337 Reviewed-by: Ian Lance Taylor --- diff --git a/src/os/user/lookup_stubs.go b/src/os/user/lookup_stubs.go index 6a20d78781..d3acbddd18 100644 --- a/src/os/user/lookup_stubs.go +++ b/src/os/user/lookup_stubs.go @@ -57,7 +57,17 @@ func current() (*User, error) { if u.Uid != "" && u.Username != "" && u.HomeDir != "" { return u, nil } - return u, fmt.Errorf("user: Current not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) + var missing string + if u.Username == "" { + missing = "$USER" + } + if u.HomeDir == "" { + if missing != "" { + missing += ", " + } + missing += "$HOME" + } + return u, fmt.Errorf("user: Current requires cgo or %s set in environment", missing) } func listGroups(*User) ([]string, error) {