diff --git a/lib/cldr/exception.ex b/lib/cldr/exception.ex index 1f07e39..8dbe299 100644 --- a/lib/cldr/exception.ex +++ b/lib/cldr/exception.ex @@ -69,3 +69,15 @@ defmodule Cldr.UnknownSubdivisionError do %__MODULE__{message: message} end end + +defmodule Cldr.UnknownInformationError do + @moduledoc """ + Exception raised when there is a missing information. + """ + + defexception [:message] + + def exception(message) do + %__MODULE__{message: message} + end +end diff --git a/lib/cldr/territory.ex b/lib/cldr/territory.ex index 9ec6d31..14d74e8 100644 --- a/lib/cldr/territory.ex +++ b/lib/cldr/territory.ex @@ -663,6 +663,10 @@ defmodule Cldr.Territory do population: 65761100 }} + iex> Cldr.Territory.info(:"155") + {:error, + {Cldr.UnknownInformationError, "No information available for :\\"155\\""}} + """ @doc since: "1.0.0" @spec info(atom() | String.t() | LanguageTag.t()) :: {:ok, map()} | {:error, {module(), String.t()}} @@ -671,7 +675,9 @@ defmodule Cldr.Territory do case Cldr.validate_territory(territory_code) do {:error, reason} -> {:error, reason} - {:ok, code} -> {:ok, @territory_info[code]} + {:ok, code} -> + info = @territory_info[code] + if info, do: {:ok, info}, else: {:error, {Cldr.UnknownInformationError, "No information available for #{inspect code}"}} end end diff --git a/mix.lock b/mix.lock index 4f73cb5..50949bc 100644 --- a/mix.lock +++ b/mix.lock @@ -6,7 +6,7 @@ "earmark": {:hex, :earmark, "1.4.5", "62ffd3bd7722fb7a7b1ecd2419ea0b458c356e7168c1f5d65caf09b4fbdd13c8", [:mix], [], "hexpm", "b7d0e6263d83dc27141a523467799a685965bf8b13b6743413f19a7079843f4f"}, "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, - "ex_cldr": {:hex, :ex_cldr, "2.38.0", "80399ccbfd996ea02f245394db83d7ce6113ed88e1e50e4695238cd9a0c258d5", [:mix], [{:cldr_utils, "~> 2.25", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.19", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: true]}], "hexpm", "8758000c97bdf4b2583c3fedd7cfa35896567a7f8351248b2faa33ba73841cc7"}, + "ex_cldr": {:hex, :ex_cldr, "2.38.1", "6dc11c1571522561fce03db680502dca2278cc20386b122ef7781b488e56dc0f", [:mix], [{:cldr_utils, "~> 2.25", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.19", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: true]}], "hexpm", "1e083be8d5f7e5d2cc993967c5d99864bacd3456b5f74d4a50985e102ad9c449"}, "ex_doc": {:hex, :ex_doc, "0.32.1", "21e40f939515373bcdc9cffe65f3b3543f05015ac6c3d01d991874129d173420", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5142c9db521f106d61ff33250f779807ed2a88620e472ac95dc7d59c380113da"}, "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, "makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},