elixir-cldr / cldr

Elixir implementation of CLDR/ICU
Other
447 stars 33 forks source link

** (RuntimeError) Locale file "de" is invalid - map key "locale_display_names" was not found. #146

Closed maennchen closed 3 years ago

maennchen commented 3 years ago

Version: 2.20.0

Error:

== Compilation error in file lib/hygeia_cldr.ex ==
** (RuntimeError) Locale file "de" is invalid - map key "locale_display_names" was not found.
    (ex_cldr 2.20.0) lib/cldr/config/config.ex:2190: anonymous fn/4 in Cldr.Config.assert_valid_keys!/2
    (elixir 1.11.4) lib/enum.ex:2193: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ex_cldr 2.20.0) lib/cldr/config/config.ex:2188: Cldr.Config.assert_valid_keys!/2
    (ex_cldr 2.20.0) lib/cldr/config/config.ex:1438: Cldr.Config.do_get_locale/3
    (ex_cldr 2.20.0) lib/cldr/compiler_locale_cache.ex:73: Cldr.Locale.Cache.do_get_locale/2
    (ex_cldr 2.20.0) lib/cldr/config/config.ex:2087: Cldr.Config.decimal_formats_for/2
    (elixir 1.11.4) lib/enum.ex:1411: Enum."-map/2-lists^map/1-0-"/2
    (ex_cldr 2.20.0) lib/cldr/config/config.ex:2076: Cldr.Config.decimal_format_list/1

The error happened in a soon-to-be-open-sourced project, I'll add @kipcole9 to the contributors so that you can have a look.

PR with Update (dependabot): https://github.com/jshmrtn/hygeia/pull/21
Failed Check: https://github.com/jshmrtn/hygeia/runs/2293523190?check_suite_focus=true

kipcole9 commented 3 years ago

This issue happens when upgrading to a new version and for some reason the locale files for that version aren't automatically downloaded at compile time. I've only seen this happen when locale files are cached in CI/CD. Any chance this is the case for your situation?

If the problem persists then either deleting the locale files or force downloading them are two options to resolve the issue.

maennchen commented 3 years ago

@kipcole9 We're caching the build dir and build_embedded set to true.

I've never encountered that problem before migrating from GitLab CI to GitHub actions...

I've implemented a cache-busting method (since apparently GitHub Actions caches can't be deleted manually) and will try again.

Thanks :)

kipcole9 commented 3 years ago

I've had one other person report the same issue so I am definitely concerned since he wasn't caching on local builds. I'm perplexed because no code in this area was touched although most definitely the locale files are all different (and do indeed include the :locale_display_names key which are currently unused but will be used in a new lib that will present a locale name in a localised manner for UI purposes).

The way the code works is that if, during compilation, the locale file isn't found it is downloaded. When a new version of a library is installed by mix then I've always seen it replace the entire deps/ex_cldr directory and therefore there are no locales and they are downloaded.

maennchen commented 3 years ago

I got the same error after a fresh cleared cache: https://github.com/jshmrtn/hygeia/pull/21/checks?check_run_id=2295044650

kipcole9 commented 3 years ago

Hmmm. Am I correct in recalling that you make use of the :data_dir configuration option on your backend? If so, then that is the directory that needs to be cleared.

Or alternatively, add the force_locale_download: true option to your backend configuration to force the locales to be downloaded. For example:

defmodule MyApp.Cldr do
  use Cldr,
    locales: [....],
    default_locale: "de",
    force_locale_download: true

end

I am now working on updating the mix cldr.install.locales <backend> mix task to take a --force_download true option but that will take a few hours to complete.

maennchen commented 3 years ago

I get the same error locally:

==>

== Compilation error in file lib/hygeia_cldr.ex ==
** (RuntimeError) Locale file "de" is invalid - map key "locale_display_names" was not found.
    (ex_cldr 2.20.0) lib/cldr/config/config.ex:2190: anonymous fn/4 in Cldr.Config.assert_valid_keys!/2
    (elixir 1.11.4) lib/enum.ex:2193: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ex_cldr 2.20.0) lib/cldr/config/config.ex:2188: Cldr.Config.assert_valid_keys!/2
    (ex_cldr 2.20.0) lib/cldr/config/config.ex:1438: Cldr.Config.do_get_locale/3
    (ex_cldr 2.20.0) lib/cldr/compiler_locale_cache.ex:73: Cldr.Locale.Cache.do_get_locale/2
    (ex_cldr 2.20.0) lib/cldr/config/config.ex:2087: Cldr.Config.decimal_formats_for/2
    (elixir 1.11.4) lib/enum.ex:1411: Enum."-map/2-lists^map/1-0-"/2
    (ex_cldr 2.20.0) lib/cldr/config/config.ex:2076: Cldr.Config.decimal_format_list/1
maennchen commented 3 years ago

@kipcole9 Never mind, I committed the locale files... Sorry for the noise.

kipcole9 commented 3 years ago

Ahhhhhh. Phew. I'm just happy to get to the bottom of the issue. I will update the documentation to note the consequences of committing locales to a repo. Thanks for letting me know.