# Undefined function is clearly defined

**URL:** <https://erlangforums.com/t/undefined-function-is-clearly-defined/4697>\
**Category:** Questions / Help\
**Tags:** erlang\
**Created:** [April 24, 2025, 10:49am UTC](https://erlangforums.com/t/undefined-function-is-clearly-defined/4697 "2025-04-24T10:49:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![korzybski](https://erlangforums.com/user_avatar/erlangforums.com/korzybski/32/2820_2.png) [@korzybski](https://erlangforums.com/u/korzybski)\
**Post date:** [April 24, 2025, 10:49am UTC](https://erlangforums.com/t/undefined-function-is-clearly-defined/4697/1 "2025-04-24T10:49:34Z")

</div>

Erlang v26. Cowboy 2.12.0.

Error:

```erlang
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

```erlang
-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…

---

<div class="post-metadata">

**Author:** ![mmin](https://erlangforums.com/user_avatar/erlangforums.com/mmin/32/2193_2.png) [@mmin](https://erlangforums.com/u/mmin)\
**Post date:** [April 24, 2025, 11:44am UTC](https://erlangforums.com/t/undefined-function-is-clearly-defined/4697/2 "2025-04-24T11:44:43Z")

</div>

Are you using `rebar3`? Seems like either `chatroom_handler` is not available to the BEAM or maybe compiled file is outdated. Can you also share the steps of how exactly you trigger the crash?

---

<div class="post-metadata">

**Author:** ![vkatsuba](https://erlangforums.com/user_avatar/erlangforums.com/vkatsuba/32/314_2.png) [@vkatsuba](https://erlangforums.com/u/vkatsuba)\
**Post date:** [April 24, 2025, 1:04pm UTC](https://erlangforums.com/t/undefined-function-is-clearly-defined/4697/3 "2025-04-24T13:04:15Z")

</div>

Few point about it:  
1 - `cowboy_websocket_handler` behavior is not exist in Cowboy \> `2.X` because it was removed  
2 - `websocket_info` should not return atom `ok`  
3 - Read documentation [Nine Nines: cowboy\_websocket(3)](https://ninenines.eu/docs/en/cowboy/2.12/manual/cowboy_websocket/)  
4 - See working examples [cowboy/examples/websocket at 2.12.0 · ninenines/cowboy · GitHub](https://github.com/ninenines/cowboy/tree/2.12.0/examples/websocket)

---

<div class="post-metadata">

**Author:** ![korzybski](https://erlangforums.com/user_avatar/erlangforums.com/korzybski/32/2820_2.png) [@korzybski](https://erlangforums.com/u/korzybski)\
**Post date:** [April 24, 2025, 3:27pm UTC](https://erlangforums.com/t/undefined-function-is-clearly-defined/4697/4 "2025-04-24T15:27:18Z")

</div>

Thank-you. The websocket example linked works out-of-the-box. Neat. Okay, I can move forward from here.
