It is a small to match on different else results in with:
with {:ok, encoded} <- File.read(...),
{:ok, value} <- Base.decode64(encoded) do
value
else
{:error, _} -> :badfile
:error -> :badencoding
end
That's because it is impossible to know from which clause the error value came from. Instead, you should normalize the return types in the clauses:
with {:ok, encoded} <- file_read(...),
{:ok, value} <- base_decode64(encoded) do
value
end
def file_read(file) do
case File.read(file) do
{:ok, contents} ->{:ok, contents}
{:error, _} -> :badfile
end
end
def base_decode64(contents) do
case Base.decode64(contents) do
{:ok, contents} ->{:ok, contents}
:error -> :badencoding
end
end
Reactions are currently unavailable
It is a small to match on different else results in with:
with {:ok, encoded} <- File.read(...), {:ok, value} <- Base.decode64(encoded) do value else {:error, _} -> :badfile :error -> :badencoding endThat's because it is impossible to know from which clause the error value came from. Instead, you should normalize the return types in the clauses:
with {:ok, encoded} <- file_read(...), {:ok, value} <- base_decode64(encoded) do value end def file_read(file) do case File.read(file) do {:ok, contents} ->{:ok, contents} {:error, _} -> :badfile end end def base_decode64(contents) do case Base.decode64(contents) do {:ok, contents} ->{:ok, contents} :error -> :badencoding end end