dwyl / mvp

šŸ“² simplest version of the @dwyl app
https://mvp.fly.dev
GNU General Public License v2.0
84 stars 2 forks source link

** (KeyError) key :status not found in: nil - `get_draft_item/1` crashes #412

Closed nelsonic closed 1 year ago

nelsonic commented 1 year ago

While QA-testing the #345 PR, getting the following error:

ā†³ AppWeb.AppLive.mount/3, at: lib/app_web/live/app_live.ex:33
[debug] QUERY OK source="items" db=0.5ms queue=0.5ms idle=534.5ms
SELECT i0."id", i0."cid", i0."person_id", i0."status", i0."text", i0."inserted_at", i0."updated_at" FROM "items" AS i0 WHERE ((i0."status" = $1) AND (i0."person_id" = $2)) [7, 0]
ā†³ App.Item.get_draft_item/1, at: lib/app/item.ex:101
[info] Sent 500 in 66ms
[debug] Converted error {:badkey, :status, nil} to 500 response
[error] #PID<0.715.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.714.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /
** (exit) an exception was raised:
    ** (KeyError) key :status 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 1.0.0) lib/app_web/live/app_live.ex:403: AppWeb.AppLive.active?/1
        (elixir 1.15.4) lib/enum.ex:4265: Enum.filter_list/2
        (app 1.0.0) lib/app_web/live/app_live.ex:486: AppWeb.AppLive.filter_items/3
        (app 1.0.0) lib/app_web/live/app_live.html.heex:146: anonymous fn/2 in AppWeb.AppLive.render/1
        (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:398: Phoenix.LiveView.Diff.traverse/7
        (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:544: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
        (elixir 1.15.4) lib/enum.ex:2510: Enum."-reduce/3-lists^foldl/2-0-"/3
        (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
        (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:139: Phoenix.LiveView.Diff.render/3
        (phoenix_live_view 0.18.18) lib/phoenix_live_view/static.ex:252: Phoenix.LiveView.Static.to_rendered_content_tag/4
        (phoenix_live_view 0.18.18) lib/phoenix_live_view/static.ex:135: Phoenix.LiveView.Static.render/3
        (phoenix_live_view 0.18.18) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
        (phoenix 1.7.7) lib/phoenix/router.ex:430: Phoenix.Router.__call__/5
        (app 1.0.0) lib/app_web/endpoint.ex:1: AppWeb.Endpoint.plug_builder_call/2
        (app 1.0.0) lib/app_web/endpoint.ex:1: AppWeb.Endpoint.call/2
        (phoenix 1.7.7) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
        (plug_cowboy 2.6.1) lib/plug/cowboy/handler.ex:11: Plug.Cowboy.Handler.init/2

Need to dig into why this is happening. šŸ§‘ā€šŸ’» šŸ”

nelsonic commented 1 year ago

Fixed in #345 by adding status?/1 function in lib/app_web/live/app_live.ex āœ