-
Notifications
You must be signed in to change notification settings - Fork 18k
time: LoadLocation returns undescriptive error messages if no time zone database is available #50248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @GreenLightning, I agree with you, the error in windows is difficult to understand without knowledge of how Goland works with Timezone, the problem here is that Windows return different errors in different situations:
But in Unix systems the return is always
I did a test in my MacOS BigSur and Windows 10, with the line below working as expected in both systems:
@ianlancetaylor , what do you think? Can I open a Merge Request with this fix and improve this error message? |
If we make such a change it should probably be done in time/sys_windows.go. It seems reasonable to do it there. |
I can't understand how changing |
My issue actually goes further than that. 1. No clear attribution of the error to the time packageAgain, "The system cannot find the path specified." is a super generic error in Windows. My suggestion would be to wrap errors that are returned to the caller, e.g. like 2. Behavior when no database is availableAs mentioned in the original description I think ignoring the error in case b) is uncontroversial. Ignoring the error in case a) makes sense in the usual case (searching multiple common locations until a valid source is found). However, when all possible locations fail with case a) then I think a different error message should be returned, explicitly stating that no time zone database could be found instead of Another case is when using |
All the discussion is about improving error messages to help the developer solve problems in the fastest way. I really don't think misspelling About improving messages to tell exactly error and not just a |
@rlanhellas In the time package the files sys_unix.go and sys_windows.go are intended to hide the differences between Unix and Windows. Checking for |
I see, because in this case, we just need to change in exactly one point and everything that is using I will suggest a Merge Request with this changing, ok @ianlancetaylor ? |
Sure, thanks, though likely won't be submitted until after the 1.18 release. |
Hello @ianlancetaylor , I made git clone and created my branch following this guide: https://go.dev/doc/contribute#sending_a_change_github. But when I try to send the
Any tips? |
@rlanhellas Changes via github are made by using forks and PRs, not pushing directly to the this (read only) repo. See github docs for more information. |
When using windows some users got a weird error (File not found) when the timezone database is not found. It happens because some methods in the time package don't treat ERROR_PATH_NOT_FOUND and ENOTDIR. To solve it was added a conversion to ENOTENT error. Fixes golang#50248
Thanks @seankhliao . @ianlancetaylor PR was opened: #50906. |
Change https://golang.org/cl/381957 mentions this issue: |
When using windows some users got a weird error (File not found) when the timezone database is not found. It happens because some methods in the time package don't treat ERROR_PATH_NOT_FOUND and ENOTDIR. To solve it was added a conversion to ENOTENT error. Fixes golang#50248
When using windows some users got a weird error (File not found) when the timezone database is not found. It happens because some methods in the time package don't treat ERROR_PATH_NOT_FOUND and ENOTDIR. To solve it was added a conversion to ENOTENT error. Fixes golang#50248
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system are you using?
Windows
What did you do?
Attempt to load time zone information using
time.LoadLocation()
and test under various conditions where no time zone database is available.This issue is made worse by the fact that the Go distribution includes a time zone database, but it is not embedded into programs being compiled by default. Therefore binaries of my program worked fine for me, but not for my users that did not have Go installed. The "works on my machine" syndrome combined with the very generic error message made identifying the root issue a lot more difficult than it should have been.
Therefore to reproduce this issue, you have to be on Windows (where no system-wide time zone database is available) and temporarily rename the folder
$GOROOT/lib/time
to something else.[If you are only here because your calls to
LoadLocation()
return the same error, the solution to this problem is toimport _ time/tzdata
to embed a fallback copy of the database into the binary. See thetime/tzdata
package documentation for more details.]What did you expect to see?
A clear error message that no time zone database is available.
What did you see instead?
This error is very generic. Compare for example with
os.Open()
, which returns an error of the formopen <filename>: The system cannot find the path specified.
. Even better would be a specific error message for the case that none of the searched locations contained a time zone database.Interestingly, if you rename the zip file inside
$GOROOT/lib/time
instead of the directory itself then you get a different nonsensical errorError: unknown time zone EST
, becauseENOENT
is ignored here. I think separate cases are confused in this logic. In the case where the time zone database is a plain directory,ENOENT
means that there is no file for this specific time zone, and ignoring the error is correct. However,ENOENT
can also be returned from loadTzinfoFromZip if the zip file cannot be found, in which case I would expect the error to be returned further. The same problem can be found here regarding theZONEINFO
environment variable.The text was updated successfully, but these errors were encountered: