elixir-cldr / cldr_units

Unit formatting (volume, area, length, ...) functions for the Common Locale Data Repository (CLDR)
Other
16 stars 13 forks source link

Unexpected return value of Cldr.Unit.to_string #1

Closed LostKobrakai closed 6 years ago

LostKobrakai commented 6 years ago

Using v0.4.2 I get the following unexpected function call result:

> Cldr.Unit.to_string(size, map_sizable_unit_to_cldr_unit(unit), style: :short, locale: "de_DE")
{:ok, {:error, {Cldr.UnknownLocaleError, "The locale "de" is not known."}}}

This doesn't seem like a desirable way of reporting an error besides the fact that "de" should be known.

LostKobrakai commented 6 years ago

Probably because pattern_for does return error tuples, but verify_unit() does only check for boolean true.

kipcole9 commented 6 years ago

Hmmmm. I'm not seeing the error. Anything else you can suggest to help me pin it down?

iex> Cldr.Unit.to_string 1234, :gallon, format: :short, locale: "de_DE"
{:ok, "1 Tsd. Gallonen"}

iex> Cldr.Unit.to_string 1234, :gallon, format: :short, locale: "ro"   
{:error, {Cldr.UnknownLocaleError, "The locale \"ro\" is not known."}}

You have helped me (a) fix a messed up doctest and (b) identify a bug in Cldr.validate_locale/1 for locale names like en-XX where XX is not a valid territory.

kipcole9 commented 6 years ago

Ahhh, can reproduce - poor handling of invalid unit types (what you said above). Fixing now.