maz

maz

With the genserver code I’m calling a python script. The script returns back asynchronously a large json blob to stdout.

What’s not clear to me is why there an error after the successful call to handle_info, ** (FunctionClauseError) no function clause matching in GrabAdapter.handle_info/2

Any insight into this? Is there a better way to do this than ports? I’ve noticed that if the JSON returned is ever malformed, The GenServer crashes and never comes back (“BROKEN PIPE”)

iex(2)> GrabAdapter.start_link("https://www.youtube.com/watch?v=ABuNwLP-z9o")
{:ok, #PID<0.518.0>}
Received message from port: {"id": "ABuNwLP-z9o", "uploader": "Phan Trieu", "uploader_id": "trieuphan1", "uploader_url": "http://www.youtube.com/user/trieuphan1", "channel_id": "UCG0SzK_t4-Ylf1yZq9Xmi_g", "channel_ur...
...wed ! Gaming Music | The Best of All Time | 2020", "_filename": "\ud83d\udd25 Top 50 NoCopyRightSounds _ Best of NCS _ Most viewed ! Gaming Music _ The Best of All Time _ 2020-ABuNwLP-z9o.mp4"}

title: 🔥 Top 50 NoCopyRightSounds | Best of NCS | Most viewed ! Gaming Music | The Best of All Time | 2020
iex(3)> [error] GenServer #PID<0.518.0> terminating
** (FunctionClauseError) no function clause matching in GrabAdapter.handle_info/2
    (grabber 0.1.0) lib/grab_adapter.ex:29: GrabAdapter.handle_info({#Port<0.19>, {:exit_status, 0}}, %{port: #Port<0.19>, ytchannel: "https://www.youtube.com/watch?v=ABuNwLP-z9o"})
    (stdlib 3.11) gen_server.erl:637: :gen_server.try_dispatch/4
    (stdlib 3.11) gen_server.erl:711: :gen_server.handle_msg/6
    (stdlib 3.11) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: {#Port<0.19>, {:exit_status, 0}}
State: %{port: #Port<0.19>, ytchannel: "https://www.youtube.com/watch?v=ABuNwLP-z9o"}
** (EXIT from #PID<0.515.0>) shell process exited with reason: an exception was raised:
    ** (FunctionClauseError) no function clause matching in GrabAdapter.handle_info/2
        (grabber 0.1.0) lib/grab_adapter.ex:29: GrabAdapter.handle_info({#Port<0.19>, {:exit_status, 0}}, %{port: #Port<0.19>, ytchannel: "https://www.youtube.com/watch?v=ABuNwLP-z9o"})
        (stdlib 3.11) gen_server.erl:637: :gen_server.try_dispatch/4
        (stdlib 3.11) gen_server.erl:711: :gen_server.handle_msg/6
        (stdlib 3.11) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

Showing Posts 1 to 3

kip

kip

ex_cldr Core Team

You are receiving a message {port, {:exit_status, code}} which you aren’t handling hence the exception. The exception messages are really quite good and in this case tell you exactly why the genserver crashed.

maz

maz OP

Thanks, yes that is the issue for sure.

If I wanted to catch this particular exception(exit_status), where does OTP allow me to? If I do this in handle_info():

    try do
      title =
      stream |> Jaxon.Stream.from_enumerable() |> Jaxon.Stream.query([:root, "title"]) |> Enum.to_list()
      IO.puts "title: #{title}"
    catch
      :error, _ -> IO.puts "there was an error with no message"
      {:error, message} -> IO.puts "there was an error: #{message}"
      {:exit_status, exit_status} -> IO.puts "posix process exited: #{exit_status}"
    end

The exception still occurs.

The “easy fix” would be to do this:

port = Port.open({:spawn, cmd}, [:binary])
instead of:
port = Port.open({:spawn, cmd}, [:binary, :exit_status])

and fully ignore exit_status but in the interests of learning, what callback should capture the original Port.open() call(putting the try-catch in handle_continue() did not seem to help)?

gregvaughn

gregvaughn

The exception occurs because a message is being delivered to your GenServer that you do not handle. You need a handle_info clause that matches what @kip said. You don’t need a try/rescue

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews