Skip to content

Commit

Permalink
Return error when Territory.info/1 has no info
Browse files Browse the repository at this point in the history
Make currency info sorted to be deterministic
Fix currency tests (CUP no longer exists, use :HT example)

# Conflicts:
#	mix.exs
#	mix.lock
#	test/territory_test.exs
  • Loading branch information
Schultzer committed Apr 25, 2024
1 parent 8a9600a commit d4b01f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/cldr/exception.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion lib/cldr/territory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()}}
Expand All @@ -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

Expand Down

0 comments on commit d4b01f6

Please sign in to comment.