mathieuprog / tz_extra

A few utilities to work with time zones in Elixir
Apache License 2.0
20 stars 2 forks source link

Compilation error #3

Closed APB9785 closed 3 years ago

APB9785 commented 3 years ago

Adding Tz and Tz_extra (following the Tz readme) gives a compilation error when starting the application:

== Compilation error in file lib/compiler_runner.ex ==
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not a nonempty list

    :erlang.hd([])
    lib/compiler.ex:143: anonymous fn/1 in TzExtra.Compiler.add_offset_data/1
    (elixir 1.12.3) lib/enum.ex:1582: Enum."-map/2-lists^map/1-0-"/2
    (elixir 1.12.3) lib/enum.ex:1582: Enum."-map/2-lists^map/1-0-"/2
    lib/compiler.ex:20: TzExtra.Compiler.compile/0
    lib/compiler_runner.ex:6: (module)
could not compile dependency :tz_extra, "mix compile" failed. You can recompile this dependency with "mix deps.compile tz_extra", update it with "mix deps.update tz_extra" or clean it with "mix deps.clean tz_extra"
mathieuprog commented 3 years ago

It looks related to this: https://github.com/mathieuprog/tz/issues/8

mathieuprog commented 3 years ago

When I create a new project, add tz_extra, and compile, it works fine for me.

mathieuprog commented 3 years ago

Could you share your environment please?

APB9785 commented 3 years ago

Sure OS 10.14.6 (Mojave) Elixir 1.12.3 Erlang 24.0.6

mathieuprog commented 3 years ago

It seems a problem concerning Mac machines it seems. But how could that be 😅

APB9785 commented 3 years ago
defp add_offset_data(time_zones) do
    Enum.map(time_zones, fn %{time_zone: time_zone_id} = time_zone ->
      {:ok, periods} = Tz.PeriodsProvider.periods(time_zone_id)

      {utc_offset, dst_offset, zone_abbr, dst_zone_abbr} =
        case hd(periods) do

I'm wondering why would one of the time_zones return an empty list of periods? Is the time_zone_id incorrect/missing?

I would look into the PeriodsProvider module but I can't seem to find it in the Tz repo.

mathieuprog commented 3 years ago

In Tz you have to look into compiler.ex, the module is being compiled in that file.

mathieuprog commented 3 years ago

Also it would be nice to add a failing test (as it works for me I can't make it fail).

APB9785 commented 3 years ago

I just unit tested this pipeline where the error occurred

IanaFileParser.time_zones_with_country(countries)
|> add_time_zone_links(get_time_zone_links_for_canonical_fun)
|> add_offset_data()
|> Enum.sort_by(
  &{&1.country && normalize_string(&1.country.name), &1.utc_offset, &1.time_zone}
)

and everything passed OK. Next I'll try it in a demo project and see if the error is still there.

APB9785 commented 3 years ago

Error is still there. tz + tz_extra in a new 1.6 project does not compile (same stacktrace as before). Here is the repo: https://github.com/APB9785/tz_error_demo

mathieuprog commented 3 years ago

I think I might encounter the error now, uhmmm.. weird. I'll look into it tomorrow.

mathieuprog commented 3 years ago

The error is cause by the option :reject_time_zone_periods_before_year. Removing this option will prevent the error. That will be a quick solution before I fix it. Note that I don't even know if this option is worth it with the newer version of Tz because I think it might make no difference memory-wise. It needs to be measured (I just don't know how yet). Also this option was more intended for embedded devices that have a very limited amount of memory.

mathieuprog commented 3 years ago

Fixed in 0.20.1

mathieuprog commented 3 years ago

By the way tz_extra has a dependency on tz so you don't need tz in your mix.exs file

APB9785 commented 3 years ago

The issue is indeed fixed for me by upgrading to 0.20.1