Skip to content

Commit aa82067

Browse files
committed
chore: include line number in the undefined filter error message
1 parent d0bb38d commit aa82067

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/solid/undefined_filter_error.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ defmodule Solid.UndefinedFilterError do
33
defexception [:filter, :loc]
44

55
@impl true
6-
def message(exception), do: "Undefined filter #{exception.filter}"
6+
def message(exception) do
7+
line = exception.loc.line
8+
reason = "Undefined filter #{exception.filter}"
9+
"#{line}: #{reason}"
10+
end
711
end

test/solid_test.exs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,20 @@ defmodule SolidTest do
289289
"user.properties.name"
290290
)
291291
end
292+
293+
test "undefined filter error message with line number" do
294+
template = "{{ var1 | not_a_filter }}"
295+
296+
assert_raise Solid.RenderError,
297+
"1 error(s) found while rendering\n1: Undefined filter not_a_filter",
298+
fn ->
299+
template
300+
|> Solid.parse!()
301+
|> Solid.render!(%{"var1" => "value"},
302+
strict_filters: true,
303+
file_system: {TestFileSystem, nil}
304+
)
305+
end
306+
end
292307
end
293308
end

0 commit comments

Comments
 (0)