Error in file view but there's no code in that view, how can I fix this?

Hello there,

I’m getting this error:

Compiling 3 files (.ex)

== Compilation error in file lib/xyz_web/views/settings_view.ex ==
** (SyntaxError) nofile:6:51: syntax error before: "info"
    (phoenix_live_view 0.16.4) lib/phoenix_live_view/html_engine.ex:363: anonymous fn/3 in Phoenix.LiveView.HTMLEngine.handle_tag_attrs/3
    (elixir 1.12.3) lib/enum.ex:2385: Enum."-reduce/3-lists^foldl/2-0-"/3
    (phoenix_live_view 0.16.4) lib/phoenix_live_view/html_engine.ex:356: Phoenix.LiveView.HTMLEngine.handle_tag_and_attrs/5
    (elixir 1.12.3) lib/enum.ex:2385: Enum."-reduce/3-lists^foldl/2-0-"/3
    (eex 1.12.3) lib/eex/compiler.ex:48: EEx.Compiler.generate_buffer/4
    (phoenix_view 1.0.0) lib/phoenix/template.ex:371: Phoenix.Template.compile/3
    (phoenix_view 1.0.0) lib/phoenix/template.ex:165: anonymous fn/4 in Phoenix.Template."MACRO-__before_compile__"/2
    (phoenix_view 1.0.0) expanding macro: Phoenix.Template.__before_compile__/1

The view code is:

defmodule XYZWeb.SettingsView do
  use XYZWeb, :view
end

Can someone points me in which direction I should start to fix this issue?

Thanks a lot,
Dominic

It is in the template.

ok, which view? I replace the entire content of the settings/index.html.heex with simple “test” in it, still the same error.

Other than that, the root.html.heex and app.html.heex are working fine with the page :index (it’s a new Phoenix app) I’m just trying to get started and it’s an almost identical thing compare to the page that came with the mix phx.new.

How do you debug those type of issues? If it’s the template, how come we don’t have the template file and line number of the causing line in question?

You are asking a question that is hard to answer without seeing the code. Maybe it is the case that the error reporting can be improved. The file fail to compile, with a message pointing to a location of line 6 column 51 of something that contain the word “info”. Can you grep your tree?

After you figure it out, can you post here and make the suggestion of how the error reporting can be improved.

Thanks for your help, I totally hear you regarding the question being very tide to my scenario.

I found the issue, that was the line that the view engine parser did not liked:

<li><a href="/account/info" {{if eq .ActiveMenu "info" }}class="is-active" {{end}}>

I’m porting an app from Go, those are Go’s template syntax, which I did not believe would cause such an issue with Phoenix view engine.

As a new comer to Elixir, the following was not clear / helpful to me:

  1. This code was in a settings/_nav.html.heex which was not even render anywhere and not in the /settings/index.html.heex . So it seems that all template files are parsed, which is good, but I was not seeing any file name, just nofile:6:51
  2. It was pointing to the SettingView which I admit, I had not even thought that the template would be the cause.

Thanks for the help

1 Like

The nofile is definitely a bug. Can you please fill in a bug report with your template or a minimum that reproduces it? Then I will take a look ASAP and see where I can improve the error message.

Edit: NVM, I see the snippet above, I am on this. :slight_smile:

2 Likes

Fixed in master!

9 Likes