]> Cypherpunks repositories - gostls13.git/commitdiff
time: improve error message for LoadLocation
authorAgniva De Sarker <agnivade@yahoo.co.in>
Sat, 30 Jun 2018 20:05:38 +0000 (01:35 +0530)
committerIan Lance Taylor <iant@golang.org>
Fri, 14 Sep 2018 20:51:22 +0000 (20:51 +0000)
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 #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>
src/time/zoneinfo_read.go
src/time/zoneinfo_test.go

index 29244db29ec67fe697205efd79d06a87ac475d60..15d6aab1dee2f696919f2018b2311bcb7ab40c6b 100644 (file)
@@ -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
index 450f5aa114aaa28caa8aeab550e015cda85baca6..4458ba8e26e1a367e1624c258b7af822fcff2367 100644 (file)
@@ -5,6 +5,7 @@
 package time_test
 
 import (
+       "errors"
        "fmt"
        "os"
        "reflect"
@@ -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"