Automatic country detection commonly panics #16

Open
opened 2026-08-22 20:31:33 +00:00 by faceguy · 0 comments
Owner

GetDeviceCountry() treats the final component of an IANA timezone as a national capital. It then dereferences the country lookup result without checking for nil.

Timezones whose representative city is not a capital, such as America/New_York or America/Chicago, therefore panic. Both CLI and TUI flows use this function when the country field is omitted.

This was reproduced with time.Local set to America/New_York; GetByCapital("New_York") returned nil and the .Alpha2 access panicked.

`GetDeviceCountry()` treats the final component of an IANA timezone as a national capital. It then dereferences the country lookup result without checking for `nil`. Timezones whose representative city is not a capital, such as `America/New_York` or `America/Chicago`, therefore panic. Both CLI and TUI flows use this function when the country field is omitted. This was reproduced with `time.Local` set to `America/New_York`; `GetByCapital("New_York")` returned `nil` and the `.Alpha2` access panicked.
faceguy self-assigned this 2026-08-22 20:31:33 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
faceguy/my-spotify-playlist-sorter-go#16
No description provided.