quda

quda

How to debug a long error stack?

How to debug, in general, an error stack like this one (bellow) ?
It’s mixed with errors coming from the Erlang dependencies. Notice it doesn’t point to a certain line of my (Elixir) code.

Where to start from, what is the error source, error initiator, errors flow? How to read it, from bottom to top or top to bottom?

[error] Ranch listener "qwerty" had connection process started with :cowboy_clear:start_link/4 at #PID<0.489.0> exit with reason:
 {
    :badarg,
    [
        {
            :erlang,
            :iolist_size,
            [
                {
                    :EXIT, #PID<0.487.0>,
                    :shutdown
                }
            ],
            [error_info: %{module: :erl_erts_errors
                }
            ]
        },
        {
            :cow_ws,
            :payload_length,
            1,
            [file: '.../deps/cowlib/src/cow_ws.erl', line: 725
            ]
        },
        {
            :cow_ws,
            :frame,
            2,
            [file: '.../deps/cowlib/src/cow_ws.erl', line: 666
            ]
        },
        {
            :cowboy_websocket,
            :websocket_send,
            2,
            [file: '.../deps/cowboy/src/cowboy_websocket.erl', line: 626
            ]
        },
        {
            :cowboy_websocket,
            :handler_call,
            6,
            [file: '.../deps/cowboy/src/cowboy_websocket.erl', line: 542
            ]
        },
        {
            :cowboy_http,
            :loop,
            1,
            [file: '.../deps/cowboy/src/cowboy_http.erl', line: 257
            ]
        },
        {
            :proc_lib,
            :init_p_do_apply,
            3,
            [file: 'proc_lib.erl', line: 226
            ]
        }
    ]
}

Thanks! :smiley:

Most Liked

kartheek

kartheek

I would start from top to bottom as this is a stack trace - look at what the exact error is and then check what data is being passing to library calls.

Error at this line (most likely as I don’t know your library versions) - matches your stack trace:

It has something to do with Payload length or indirectly Payload itself?

Little more context about the app would help - is this phoenix app or elixir app with cowboy web sockets ? What versions of libraries you are using?

al2o3cr

al2o3cr

Start from the top - this is the root cause of the error - :erlang.iolist_size/1 is raising :badarg. The most common cause of this is passing something in that’s not the right shape.

The next two frames for :cow_ws.payload_length and :cow_ws.frame aren’t particularly interesting.

The frame for :cow_ws.websocket_send gives us another piece of information: we’re trying to send whatever the badly-shaped data is down a websocket

But the really important one is the frame after that: :cow_ws.handler_call. This is the “brains” of the websocket handler:

This is why the stack doesn’t have any application code in it - the application code is called in the first part of handler_call, and then the result of that is what’s being handled when the crash happens.

Check your code that’s sending data via websockets; has a stray {:ok, "data that should be sent"} snuck in someplace where you’re expecting just "data that should be sent"?

al2o3cr

al2o3cr

cowboy_websocket expects frames to match the cow_ws:frame type:

frame() :: {text, iodata()}
    | {binary, iodata()}
    | ping | {ping, iodata()}
    | pong | {pong, iodata()}
    | close | {close, iodata()} | {close, close_code(), iodata()}

close_code() :: 1000..1003 | 1006..1011 | 3000..4999

{:ok, "{\"some\":\"json data\"}"} is none of those, and it’s not an iodata either - so an error occurs.

I can’t offer you any shortcut - if you’re going to write code that interfaces with Erlang libraries (like cowboy_websocket) you’re going to need to learn some Erlang.

LostKobrakai

LostKobrakai

The comparison is a bit off. It‘s more like Scala and Java. Both run on the JVM and can interop with each other. If you depend from a Scala project on a Java library you’re better off knowing Java as well.

I also found that erlang becomes easier and easier to read with getting to know elixir.

cmo

cmo

I mean learn to love it for your own satisfaction in life. It’s not going to split from Erlang and life is too sweet to worry about things out of your control.

And yes your analogy is off. You are largely freed from writing C by the Erlang team, who are writing it for you.

Where Next?

Popular in Questions Top

JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
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 49522 488
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement