Erlang v26. Cowboy 2.12.0.
Error:
Inside chatroom_handler:init
=CRASH REPORT==== 23-Apr-2025::23:20:46.786362 ===
crasher:
initial call: cowboy_clear:connection_process/4
pid: <0.216.0>
registered_name: []
exception error: undefined function chatroom_handler:websocket_handle/2
in function cowboy_websocket:handler_call/6 (/home/xxx/chat3/_build/default/lib/cowboy/src/cowboy_websocket.erl, line 528)
in call from cowboy_http:loop/1 (/home/xxx/chat3/_build/default/lib/cowboy/src/cowboy_http.erl, line 253)
chatroom_handler.erl
-module(chatroom_handler).
-behavior(cowboy_websocket_handler).
-export([init/2]).
-export([websocket_init/1]).
-export([websocket_handle/2]).
-export([websocket_info/2]).
-export([terminate/3]).
init(Request, State) ->
io:format("Here 1~n"), % appears in shell
{cowboy_websocket, Request, State}.
websocket_init(State) ->
io:format("Here 2~n"), % never appears in shell
{ok, State}.
websocket_handle(Frame = {text, _}, State) ->
{reply, Frame, State}.
websocket_info(Info, State) ->
io:format("Here 3~n").
terminate(Reason, PartialRequest, State) ->
ok.
So… what am I doing wrong?
Me complaining:
It’s literally crazy to me that something like Phoenix sits on top of Cowboy, yet the documentation for Cowboy is the way it is right now. Why is there not a single whole-file example in the official Cowboy doc? I can think of a reason…