I have been learning how to build erlang application with rebar3. What I have done is firstely; creating new app template using the below command
rebar3 new app chat
then, I copied my hole project to the src folder of the template that I created. Finally, I altered the chat_sup.erl
to look like below:
-module(chat_sup).
-behaviour(supervisor).
-export([start_link/0]).
-export([init/1]).
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
init([]) ->
SupFlags = #{strategy => one_for_all,
intensity => 3,
period => 3},
ChildSpecs = [
#{id => worker, start => {chatapp_server, start_link, []}}
],
{ok, {SupFlags, ChildSpecs}}.
where, chatapp_server
the server file to be supervised and it looks like below
-module(chatapp_server).
-export([start/0, start_link/0, stop/0,wind_rooms/0]).
-export([init/0]).
-include("chatapp_config.hrl").
start() ->
register(?SERVER, spawn(?MODULE, init, [])).
start_link() ->
register(?SERVER, spawn_link(?MODULE, init, [])).
......................
.........................
............................
end.
I kept the chat_app.erl
as it with no changes which is:
-module(chat_app).
-behaviour(application).
-export([start/2, stop/1]).
start(_StartType, _StartArgs) ->
chat_sup:start_link().
stop(_State) ->
ok.
when I run the project using:
rebar3 shell
I got the follwoing errors:
PS F:\chat> rebar3 shell
===> Verifying dependenciesâŠ
===> Analyzing applicationsâŠ
===> Compiling chat
Erlang/OTP 27 [erts-15.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]
=SUPERVISOR REPORT==== 8-Aug-2024::03:50:48.655000 ===
supervisor: {local,chat_sup}
errorContext: start_error
reason: true
offender: [{pid,undefined},
{id,worker},
{mfargs,{chatapp_server,start_link,}},
{restart_type,permanent},
{significant,false},
{shutdown,5000},
{child_type,worker}]
===> Failed to boot chat for reason {{shutdown,
{failed_to_start_child,worker,true}},
{chat_app,start,[normal,]}}
=INFO REPORT==== 8-Aug-2024::03:50:48.656000 ===
application: chat
exited: {{shutdown,{failed_to_start_child,worker,true}},
{chat_app,start,[normal,]}}
type: temporary
=CRASH REPORT==== 8-Aug-2024::03:50:48.656000 ===
crasher:
initial call: application_master:init/3
pid: <0.229.0>
registered_name:
exception exit: {{shutdown,{failed_to_start_child,worker,true}},
{chat_app,start,[normal,]}}
in function application_master:init/3 (application_master.erl, line 143)
ancestors: [application_controller,<0.10.0>]
message_queue_len: 1
messages: [{âEXITâ,<0.230.0>,normal}]
links: [<0.45.0>]
dictionary:
trap_exit: true
status: running
heap_size: 233
stack_size: 29
reductions: 68
neighbours:
Eshell V15.0 (press Ctrl+G to abort, type help(). for help)
what the wrong I am doing here please ?