feviskus

feviskus

Failing task in start_async not calling appropriate handle_async({:error}) callback

Hello there,

I inherited a rather complicated LiveComponent from a colleague: due to complex JS there’s no render/1 function, only update/2.
I have a hook which publishes an event to said component, which should then start an async operation on the backend.

  @impl true
  def handle_event("classify-users", _params, socket) do
    socket =
      socket
      |> start_async(:perform_classification, fn ->
        raise "Some error"
      end)

    {:noreply, socket}
  end

I expect this code to eventually call the handle_async callback:

 @impl true
  def handle_async(:perform_classification, {:exit, reason}, socket) do
    Logger.error("Could not perform classification: #{reason}")
    {:noreply,
     push_event(socket, "classification-finished", %{class: "Error #{reason}"})}
  end

However, the component simply crashes and I don’t know why it never executes said handle_async function.
Any idea?

Marked As Solved

feviskus

feviskus

thanks, but after careful investigation I came to the conclusion that it’s a layer 8 problem:

The :exit-matching function was indeed called but not logged as the interpolation of #{reason} raises an Exception if reason is a tuple…

[error] Task #PID<0.12550.0> started from #PID<0.12511.0> terminating
** (RuntimeError) Some error
    handle_event/3
    (phoenix_live_view 0.20.17) lib/phoenix_live_view/async.ex:220: Phoenix.LiveView.Async.do_async/5
    (elixir 1.18.2) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
Function: #Function<7.25247813/0 in Phoenix.LiveView.Async.run_async_task/5>
    Args: []
[error] GenServer #PID<0.12511.0> terminating
** (Protocol.UndefinedError) protocol String.Chars not implemented for type Tuple

Got value:

    {%RuntimeError{message: "Some error"},
     [...]

Using "#{inspect(reason)}" instead.

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New

We're in Beta

About us Mission Statement