Failure to compile after updating to live view 0.18.3 related to phoenix components

I would really appreciate any guidance that I can get :grinning:

After updating to Live View 0.18.3 from 0.16.x the app will no longer compile and there is very little debugging information. I’m sure it has to do with one or more of my components not conforming to the new API, but I have a lot of components and I’m trying to figure out where to start.

This is the entire stack trace I’m getting:

Compiling 268 files (.ex)
** (EXIT from #PID<0.95.0>) an exception was raised:
    ** (ArgumentError) argument error
        (phoenix_live_view 0.18.3) lib/phoenix_component/declarative.ex:1091: anonymous fn/5 in Phoenix.Component.Declarative.verify/3
        (stdlib 4.1.1) maps.erl:411: :maps.fold_1/3
        (phoenix_live_view 0.18.3) lib/phoenix_component/declarative.ex:1090: Phoenix.Component.Declarative.verify/3
        (phoenix_live_view 0.18.3) lib/phoenix_component/declarative.ex:1034: anonymous fn/3 in Phoenix.Component.Declarative.__verify__/2
        (elixir 1.14.1) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
        (phoenix_live_view 0.18.3) lib/phoenix_component/declarative.ex:1031: Phoenix.Component.Declarative.__verify__/2
        (elixir 1.14.1) lib/enum.ex:975: Enum."-each/2-lists^foreach/1-0-"/2
        (elixir 1.14.1) lib/module/parallel_checker.ex:239: Module.ParallelChecker.check_module/2
        (elixir 1.14.1) lib/module/parallel_checker.ex:78: anonymous fn/5 in Module.ParallelChecker.spawn/3


live_view code is crashing while passing arguments to for loop . Please log a bug in here - issues .

I realised that if I don’t see a proper error message and see ArgumentError, CaseCondError, etc without a proper context like source file name, line number, etc relating to code from project files - it is a bug in live_view. Happened to me earlier.

If you can’t figure out what is causing this crash - you can fork the project and add some logger statements around the line 1091 to know which component is causing this crash?

Thanks kartheek. I was just coming back to update this post because that’s exactly what I did. I wrapped it in a try…catch and logged the information which allowed me to work through my components and get everything fixed. It took some time to get all of the components working but it’s worth it for the new API which I really like.

1 Like

Did you find out why this is happening? May be it will help others.

tldr; All attributes passed to a Phoenix.Component function that are not either prefixed with phx- , aria- , data-, or are one of the html global elements must be declared with the attr macro.

In most cases my problem was not using the attr macro to declare attributes for function components. I thought the attr macro was just added for new functionality. I did not realize that most attributes must be declared. Since all my components were built before the attr macro, none of them had attributes specified.

Since the error message wasn’t helpful, once I figured out the issue I added some simple logging to the code you mentioned so I could see where the issues were.

I replaced this code:

with something like the following (this is just an example that may need some tweaks, I forget exactly what I used):

  try do
    for {name, {line, _column, _type_value}} <- attrs,
        not (global_attr && __global__?(caller_module, Atom.to_string(name), global_attr)) do
      message = "undefined attribute \"#{name}\" for component #{component_fa(call)}"
      warn(message, call.file, line)
    e ->
      IO.puts ~s(
         #{inspect caller_module}

         #{inspect attrs}
      reraise e, __STACKTRACE__
1 Like