Skip to content

Error when leaving contact import page #225

Description

@katafrakt

Whenever I leave the contact import page, no matter if I performed an import or not, I'm seeing this error in the server log:

[error] GenServer #PID<0.1362.0> terminating
** (FunctionClauseError) no function clause matching in KeilaWeb.ContactImportLive.terminate/2
    (keila 0.12.2) lib/keila_web/live/contact_import_live.ex:91: KeilaWeb.ContactImportLive.terminate({:shutdown, :closed}, #Phoenix.LiveView.Socket<id: "phx-F3c7XwN3eiYkhAeG", endpoint: KeilaWeb.Endpoint, view: KeilaWeb.ContactImportLive, parent_pid: nil, root_pid: #PID<0.1362.0>, router: nil, assigns: %{__changed__: %{}, current_project: %Keila.Projects.Project{__meta__: #Ecto.Schema.Metadata<:loaded, "projects">, id: "np_RzejQdqB", name: "test", group_id: "nag_G6amQa48", group: #Ecto.Association.NotLoaded<association :group is not loaded>, inserted_at: ~U[2023-04-25 10:56:46Z], updated_at: ~U[2023-04-25 10:56:46Z]}, flash: %{}, import_error: nil, import_progress: 0, import_replace: true, import_total: 0, live_action: nil, uploaded_files: [], uploads: %{__phoenix_refs_to_names__: %{"phx-F3c7YRXmtSt2DgiG" => :csv}, csv: #Phoenix.LiveView.UploadConfig<name: :csv, max_entries: 1, max_file_size: 8000000, entries: [], accept: ".csv,.txt,.tsv", ref: "phx-F3c7YRXmtSt2DgiG", errors: [], auto_upload?: false, progress_event: nil, ...>}}, transport_pid: #PID<0.1356.0>, ...>)
    (stdlib 4.1.1) gen_server.erl:1161: :gen_server.try_terminate/3
    (stdlib 4.1.1) gen_server.erl:1351: :gen_server.terminate/10
    (stdlib 4.1.1) proc_lib.erl:250: :proc_lib.wake_up/3

This is because implementation of terminate callback for ContactImportLive only works if the reason is :normal:

  @impl true
  def terminate(:normal, socket) do
    if socket.assigns.csv_filename do
      File.rm(socket.assigns.csv_filename)
    end
  end

However, here the reason is {:shutdown, :closed}. I'm not sure when (if ever) LiveViews terminate with :normal, but perhaps the implementation of terminate should not check for reason and always try to delete the uploaded file?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions