From 01a07466bbb3f1a7bec766fc073d82835a252ffb Mon Sep 17 00:00:00 2001 From: shaolang Date: Tue, 3 Dec 2024 18:14:51 +0800 Subject: [PATCH] Fix bug in error-raising variants --- lib/jaqex.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/jaqex.ex b/lib/jaqex.ex index c078d00..aeb6d6e 100644 --- a/lib/jaqex.ex +++ b/lib/jaqex.ex @@ -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 @@ -29,7 +29,7 @@ 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 """ @@ -37,7 +37,7 @@ defmodule Jaqex do """ @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 @@ -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}