Skip to content

Commit

Permalink
time: improve error message for LoadLocation
Browse files Browse the repository at this point in the history
Currently, when a tz file was being checked inside a zoneInfo dir,
a syscall.ENOENT error was being returned, which caused it to look
in the zoneinfo.zip file and return an error for that case.

We return a syscall.ENOENT error for the zip file case too, so that
it falls through to the end of the loop and returns an uniform error
for both cases.

Fixes golang#20969

Change-Id: If1de068022ac7693caabb5cffd1c929878460140
Reviewed-on: https://go-review.googlesource.com/121877
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
agnivade authored and ianlancetaylor committed Sep 14, 2018
1 parent 0e21cc2 commit 7df585d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/time/zoneinfo_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func loadTzinfoFromZip(zipfile, name string) ([]byte, error) {
return buf, nil
}

return nil, errors.New("cannot find " + name + " in zip file " + zipfile)
return nil, syscall.ENOENT
}

// loadTzinfoFromTzdata returns the time zone information of the time zone
Expand Down
11 changes: 11 additions & 0 deletions src/time/zoneinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package time_test

import (
"errors"
"fmt"
"os"
"reflect"
Expand Down Expand Up @@ -36,6 +37,16 @@ func TestEnvVarUsage(t *testing.T) {
}
}

func TestBadLocationErrMsg(t *testing.T) {
time.ResetZoneinfoForTesting()
loc := "Asia/SomethingNotExist"
want := errors.New("unknown time zone " + loc)
_, err := time.LoadLocation(loc)
if err.Error() != want.Error() {
t.Errorf("LoadLocation(%q) error = %v; want %v", loc, err, want)
}
}

func TestLoadLocationValidatesNames(t *testing.T) {
time.ResetZoneinfoForTesting()
const env = "ZONEINFO"
Expand Down

0 comments on commit 7df585d

Please sign in to comment.