1
0
mirror of https://github.com/golang/go synced 2024-09-30 17:38:33 -06:00

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/3984
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
David Symonds 2015-02-06 16:58:07 +11:00
parent a35181ba7f
commit 8bf13838eb
4 changed files with 18 additions and 8 deletions

View File

@ -74,3 +74,5 @@ func preadn(fd uintptr, buf []byte, off int) error {
}
return nil
}
func isNotExist(err error) bool { return err == syscall.ENOENT }

View File

@ -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.name = name
return z, nil
z, err := loadZoneFile(runtime.GOROOT()+"/lib/time/zoneinfo.zip", name)
if err != nil {
return nil, err
}
return nil, errors.New("unknown time zone " + name)
z.name = name
return z, nil
}
func forceZipFileForTesting(zipOnly bool) {

View File

@ -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)
}

View File

@ -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.name = name
return z, nil
z, err := loadZoneFile(runtime.GOROOT()+`\lib\time\zoneinfo.zip`, name)
if err != nil {
return nil, err
}
return nil, errors.New("unknown time zone " + name)
z.name = name
return z, nil
}
func forceZipFileForTesting(zipOnly bool) {