Skip to content

Commit

Permalink
troubleshoot
Browse files Browse the repository at this point in the history
  • Loading branch information
Dalgona committed Aug 9, 2020
1 parent c68038d commit 4faf794
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/serum/template/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ defmodule Serum.Template.Compiler do
@spec compile_file(V2.File.t(), options()) :: Result.t(Template.t())
defp compile_file(file, options) do
Result.run do
ast <- compile_string(file.in_data, file)
ast <- compile_string(file.in_data, file, options)
name = Path.basename(file.src, ".html.eex")
template = Serum.Template.new(ast, name, options[:type], file)

Expand All @@ -78,6 +78,11 @@ defmodule Serum.Template.Compiler do
{:ok, {:__block__, [], [@inject, EEx.compile_string(string, options)]}}
rescue
e in [SyntaxError, TokenMissingError, EEx.SyntaxError] ->
if options[:_TROUBLESHOOT] do
IO.puts("\n====== EXCEPTION RESCUED: ======\n#{inspect(e)}\n")
IO.puts("\n====== STACKTRACE: ======\n#{inspect(__STACKTRACE__, pretty: true)}\n")
end

Result.fail(Exception: [e, __STACKTRACE__], file: file, line: e.line)
end
end
3 changes: 2 additions & 1 deletion test/serum/template/compiler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ defmodule Serum.Template.CompilerTest do
|> Enum.map(&V2.File.read/1)
|> Enum.map(fn {:ok, file} -> file end)

{:error, %Error{caused_by: errors}} = TC.compile_files(files, type: :template)
{:error, %Error{caused_by: errors}} =
TC.compile_files(files, type: :template, _TROUBLESHOOT: true)

assert length(errors) === length(files)
end
Expand Down

0 comments on commit 4faf794

Please sign in to comment.