quda

quda

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:

First 10 of 10 Posts Switch mode

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"?

quda

quda OP

Thanks a lot @al2o3cr and @kartheek. Now is clear for me… somewhat.

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?

No Phoenix, just Plug.Cowboy. v.2.5.2

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" ?

The payload is {:ok, obj}, where obj is a json. Then I still can’t get it why this error is raised.

This is just one example of this kind of errors. I’ve encountered many as such and didn’t know where to start from. I was just looking for a rationale/pattern for analyzing them.
That’s why I was asking initially how to debug these “in general” and not particularly this error above.

An observation: it’s very frustrating that most of these Elixir error stacks go deep to the underlying Erlang libraries. As my Erlang knowledge being nil, it’s almost impossible for me to understand and debug them. :pensive:

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.

quda

quda OP

Finally solved this one, I was mistakenly sending the websocket’s state instead of the json serialized payload. Now it’s fine, thanks again @al2o3cr. However, this error stack so cryptic and unfriendly for (just) Elixir coder. :-1:t4:
So, you’re right, I need to get my hands dirty with Erlang. In this case I need to understand the underlying implementation of this bloody cowboy_websocket. :face_with_raised_eyebrow:iodata and such.
I consider a huge drawback for Elixir that is based so much on Erlang’s libraries. (immaturity ?). This remembers me Java in the late '90s. Or C#'s infancy.

cmo

cmo

It’s the other way round. Elixir’s biggest strength is that it is built on the solid foundation of Erlang, and it interops with it fairly seamlessly. I recommend you learn to love Erlang, as there is no escaping it :wink:

quda

quda OP

Love… I really don’t think so. :nauseated_face: It’s more about necessity. This reminds me of Tcl, had to learn it ages ago, to perform some tasks. I did it, but hated it. Even today I have bad dreams about it.
I really love Elixir instead. Too bad they are linked together at the Elixir use level. IMO Elixir should evolve into a complete abstraction from Erlang.

LE: Java lang is running on JVM, written in C/C++. One doesn’t have to know those in order to master Java. Right ?

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.

quda

quda OP

My analogy might be off but I hope you got the idea.

You are largely freed from writing C by the Erlang team, who are writing it for you.

I would prefer to debug errors in C (a common language) rather than in Erlang. :stuck_out_tongue_winking_eye:

Anyway, let’s end this.
Thanks everybody,
Cheers.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement