Skip to content

Commit

Permalink
Fix dialyzer errors
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Jul 1, 2024
1 parent e31fe6a commit 4e85162
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lib/vnu/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ defmodule Vnu.CLI do

results =
Enum.map(files, fn file ->
with {:file, {:ok, document}} <- {:file, File.read(file)},
{:validation, {:ok, result}} <- {:validation, validate_function.(document, opts)} do
with {:ok, document} <- read_file(file),
{:ok, result} <- validate_document(file, document, opts, validate_function) do
messages =
result.messages
|> Vnu.Formatter.sort()
Expand All @@ -80,12 +80,6 @@ defmodule Vnu.CLI do

{file,
%{error_count: error_count, warning_count: warning_count, info_count: info_count}}
else
{:file, {:error, error}} ->
Mix.raise("File #{file} could not be read:\n #{inspect(error)}")

{:validation, {:error, error}} ->
Mix.raise("Could not finish validating #{file}:\n #{inspect(error)}")
end
end)

Expand All @@ -97,6 +91,26 @@ defmodule Vnu.CLI do
handle_total_counts(results, total_counts, fail_on_warnings?)
end

defp read_file(file) do
case File.read(file) do
{:ok, content} ->
{:ok, content}

{:error, error} ->
Mix.raise("Could not finish validating #{file}:\n #{inspect(error)}")
end
end

defp validate_document(file, document, opts, validate_function) do
case validate_function.(document, opts) do
{:ok, result} ->
{:ok, result}

{:error, error} ->
Mix.raise("Could not finish validating #{file}:\n #{inspect(error)}")
end
end

@doc false
def format_to_function_and_pretty_name(format) do
case format do
Expand Down

0 comments on commit 4e85162

Please sign in to comment.