mirror of
https://github.com/golang/go
synced 2024-11-18 12:04:57 -07: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:
parent
a35181ba7f
commit
8bf13838eb
@ -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.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) {
|
||||
|
@ -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.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) {
|
||||
|
Loading…
Reference in New Issue
Block a user