Skip to content

Commit 0a49d62

Browse files
authored
[minielixir] handle empty cond & other errors (#1473)
1 parent d06438f commit 0a49d62

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/sequin/consumers/consumers.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,9 @@ defmodule Sequin.Consumers do
13761376
[]
13771377
end
13781378
end
1379+
rescue
1380+
error ->
1381+
[code: "validation failed: #{Exception.message(error)}"]
13791382
end
13801383

13811384
def safe_evaluate_code(code) do

lib/sequin/transforms/minielixir/validator.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ defmodule Sequin.Transforms.MiniElixir.Validator do
214214
defp good({:defmodule, _, _}), do: {:error, :validator, "defining modules is not allowed"}
215215
defp good({:def, _, _}), do: {:error, :validator, "defining functions is not allowed"}
216216
defp good({:defp, _, _}), do: {:error, :validator, "defining functions is not allowed"}
217-
defp good({:cond, _meta, [[{:do, body}]]}), do: check_body(body)
217+
defp good({:cond, _meta, [[{:do, body}]]}) when is_list(body), do: check_body(body)
218+
# Empty cond has an empty block not an empty list
219+
defp good({:cond, _meta, [[{:do, body}]]}), do: check(body)
218220

219221
defp good({:=, _meta, [l, r]}) do
220222
with {:ok, bound} = __MODULE__.PatternChecker.extract_bound_vars(l) do

test/sequin/minielixir_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,16 @@ defmodule Sequin.MiniElixirTest do
396396
end
397397
)
398398
end
399+
400+
test "empty cond expression" do
401+
assert :ok =
402+
Validator.check(
403+
quote do
404+
cond do
405+
end
406+
end
407+
)
408+
end
399409
end
400410

401411
defp get_vars(ast) do

0 commit comments

Comments
 (0)