Skip to content

Commit

Permalink
Fix bug in error-raising variants
Browse files Browse the repository at this point in the history
  • Loading branch information
shaolang committed Dec 3, 2024
1 parent 0b2e5b6 commit 01a0746
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/jaqex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Jaqex do
"""
@spec filter(String.t(), String.t(), Path.t()) :: {:ok, term} | {:error, term}
def filter(json_doc, code, path \\ "") do
filter!(json_doc, code, path)
{:ok, filter!(json_doc, code, path)}
rescue
e -> error(e)
end
Expand All @@ -29,15 +29,15 @@ defmodule Jaqex do
@spec filter!(String.t(), String.t(), Path.t()) :: term
def filter!(json_doc, code, path \\ "") do
result = nif_filter(json_doc, code, path)
{:ok, if(length(result) == 1, do: List.first(result), else: result)}
if(length(result) == 1, do: List.first(result), else: result)
end

@doc """
Filter the JSON in the given file with the given j(a)q code.
"""
@spec filter_file(Path.t(), String.t(), Path.t()) :: {:ok, term} | {:error, term}
def filter_file(fname, code, path \\ "") do
filter_file!(fname, code, path)
{:ok, filter_file!(fname, code, path)}
rescue
e -> error(e)
end
Expand All @@ -48,7 +48,7 @@ defmodule Jaqex do
@spec filter_file!(Path.t(), String.t(), Path.t()) :: term
def filter_file!(fname, code, path \\ "") do
result = nif_filter_file(fname, code, path)
{:ok, if(length(result) == 1, do: List.first(result), else: result)}
if(length(result) == 1, do: List.first(result), else: result)
end

defp error(%ErlangError{original: err}), do: {:error, err}
Expand Down

0 comments on commit 01a0746

Please sign in to comment.