Syntax error: KeyError) key :color not found in: nil (but app works on a different machine)

I have three instances of an app on different machines that I have updates a LiveView page to.

These three machines are Local Machine, a Dev Machine and Live Machine.

The app on Local Machine is a clone of the Phoenix App on Live Machine. I literally copied it over before working on it.

The live view page I edited is named: page_live.ex
On Local Machine I edited page_live.ex and then copied it to Dev Machine in the same directory it was in on the Live Machine.

The change worked and rendered as expected and Dev Machine updated accordingly. I thought "hey , I’ll update the Live Machine " now.

On my Live machine when I upload the file I get this syntax error:

KeyError at GET /
key :color not found in: nil. If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
# KeyError at GET /

Exception:

    ** (KeyError) key :color not found in: nil. If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
        (app 0.1.0) lib/app_web/live/page_live.ex:506: anonymous fn/4 in AppWeb.PageLive.render/1
        (elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
        (app 0.1.0) lib/app_web/live/page_live.ex:501: anonymous fn/2 in AppWeb.PageLive.render/1

All the dependencies I see between systems are the same. The Dev Machine and the Live Machine have the same version of Elixir.

What can be wrong?

I have not run phx.deps.get yet as I am waiting for my server admin buddy to make a backup first but I am unsure how that would fix this as I did not need to do it with the Dev Machine

Thank you.

EDIT

I just grabbed all the code off Live Machine and re-copied it to another directory on my Local Machine.

Runing it gave me some non related errors so I deleted the .build directory and did mix phx.digest

I manually copied over the new page_live.ex file and it works with no error.

I am not sure why copying it over to directly to Live Machine doesn’t work the same.

Like I said, maybe it will be solved by a rebuild but it’s still a weird error.

This error message is the symptom - you’ve got code that does some_variable.color when some_variable is bound to nil.

The cause is whatever’s putting nil in some_variable, when you’re expecting a map to be there.

Yes that is what the error is saying but it doesn’t help me diagnose the problem when viewed in the context of the post. One thing I left out is that my Local Machine instance was a clone of my Live Machine instance. I’ll add that info to the initial post.

EDIT
@al2o3cr I am assuming the structure of data for all databases were exactly the same. I think that was the wrong assumption.

The code can be the same but if the app is fetching data from somewhere then that data can differ. The binding you are expecting to be a map, what is its value coming from?

1 Like

I understand they’re running the same code - my point is that something in lib/app_web/live/page_live.ex is getting different data at runtime.

Showing that code would be useful to diagnose further.

3 Likes

Yeah I see. I just made an edit above

I am assuming the structure of data for all databases were exactly the same. I think that was the wrong assumption. :frowning:

Even if the structure of the tables were the same, having different rows of data in the database can cause nil values to be returned

1 Like