Commit 8bf13838 authored by David Symonds's avatar David Symonds

time: return informative errors when failing to load timezone data.

If we cannot load timezone information for a reason other than the
zoneinfo file not existing, return it since that will be much more
useful in debugging failures than "unknown time zone XYZ".

Fixes #9723.

Change-Id: I3aa5774859cec28e584d16bcc1fef0705d95288c
Reviewed-on: https://go-review.googlesource.com/3984Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent a35181ba
......@@ -74,3 +74,5 @@ func preadn(fd uintptr, buf []byte, off int) error {
}
return nil
}
func isNotExist(err error) bool { return err == syscall.ENOENT }
......@@ -148,11 +148,12 @@ func initLocal() {
}
func loadLocation(name string) (*Location, error) {
if z, err := loadZoneFile(runtime.GOROOT()+"/lib/time/zoneinfo.zip", name); err == nil {
z, err := loadZoneFile(runtime.GOROOT()+"/lib/time/zoneinfo.zip", name)
if err != nil {
return nil, err
}
z.name = name
return z, nil
}
return nil, errors.New("unknown time zone " + name)
}
func forceZipFileForTesting(zipOnly bool) {
......
......@@ -74,11 +74,17 @@ func initLocal() {
}
func loadLocation(name string) (*Location, error) {
var firstErr error
for _, zoneDir := range zoneDirs {
if z, err := loadZoneFile(zoneDir, name); err == nil {
z.name = name
return z, nil
} else if firstErr == nil && !isNotExist(err) {
firstErr = err
}
}
if firstErr != nil {
return nil, firstErr
}
return nil, errors.New("unknown time zone " + name)
}
......@@ -260,11 +260,12 @@ func initLocal() {
}
func loadLocation(name string) (*Location, error) {
if z, err := loadZoneFile(runtime.GOROOT()+`\lib\time\zoneinfo.zip`, name); err == nil {
z, err := loadZoneFile(runtime.GOROOT()+`\lib\time\zoneinfo.zip`, name)
if err != nil {
return nil, err
}
z.name = name
return z, nil
}
return nil, errors.New("unknown time zone " + name)
}
func forceZipFileForTesting(zipOnly bool) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment