From: Florian Uekermann Date: Fri, 1 Dec 2017 19:01:55 +0000 (+0100) Subject: time: return first error in unsuccessful calls to LoadLocation X-Git-Tag: go1.12beta1~923 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=048de7b1fdfbedd99af4b1f14133ac7e221cb79a;p=gostls13.git time: return first error in unsuccessful calls to LoadLocation Unsuccessful calls to LoadLocation previously returned the first error encountered while traversing the default list of sources, but ignored errors from sources specified by ZONEINFO. Whether errors indicating missing zones or sources were ignored in this process differed between kinds of sources. With this change, unsuccessful calls to LoadLocation always return the first error, not counting errors indicating missing zones or sources. Change-Id: Ief2c088f1df53d974b837e6565e784c2b9928ef4 Reviewed-on: https://go-review.googlesource.com/c/81595 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- diff --git a/src/time/zoneinfo.go b/src/time/zoneinfo.go index d2bc642d81..54c76f09e1 100644 --- a/src/time/zoneinfo.go +++ b/src/time/zoneinfo.go @@ -288,14 +288,23 @@ func LoadLocation(name string) (*Location, error) { env, _ := syscall.Getenv("ZONEINFO") zoneinfo = &env }) + var firstErr error if *zoneinfo != "" { if zoneData, err := loadTzinfoFromDirOrZip(*zoneinfo, name); err == nil { if z, err := LoadLocationFromTZData(name, zoneData); err == nil { return z, nil } + firstErr = err + } else if err != syscall.ENOENT { + firstErr = err } } - return loadLocation(name, zoneSources) + if z, err := loadLocation(name, zoneSources); err == nil { + return z, nil + } else if firstErr == nil { + firstErr = err + } + return nil, firstErr } // containsDotDot reports whether s contains "..".