Bercovici Adrian
Bercovici Adrian

Reputation: 9380

Can not start Erlang Application due to bad return error

I have a simple erlang application and i am trying to start it to no avail getting a bad return error:

> {error,
>     {bad_return,
>         {{mapp,start,[normal,[]]},
>          {'EXIT',
>              {undef,
>                  [{mapp,start,[normal,[]],[]},
>                   {application_master,start_it_old,4,
>                       [{file,"application_master.erl"},{line,277}]}]}}}}}

.app

{
    application,mapp,
    [
        {vsn,"1.0.0"},
        {description,"some description"},
        {mod,{mapp,[]}},
        {modules,[mapp,m1]}
    ]   
}.

Folder structure:

-root
  -mapp.app
  -src
     -m1.erl
     -mapp.erl
  -include
      -state.hrl
  -ebin

Application

-module(mapp).
-behaviour(application).
-export([start/2,stop/1]).

start(normal,_Args)->
    Pid=m1:start_link(),
    {ok,Pid}.

stop(State)->ok.

Module

-module(m1).
-include("r.hrl").
-export([start_link/0]).

start_link()->
    Pid=spawn_link(?MODULE,serv,#state{count=2}),
    Pid.
serv(State=#state{count=C})->
    receive 
        {From,MSG} ->From ! {ok,MSG},
                     serv(State#state{count=C=1})
    end.

.hrl

-record(state,{
    count=0
    }).

So my m1 module returns a Pid.I comply to the application:start/2 return type and return a {ok,Pid}. What is wrong here ? I have tried both with Pid and {ok,Pid} to no avail.

Upvotes: 0

Views: 477

Answers (1)

José M
José M

Reputation: 3509

The error states that the mapp:start/2 is undef. Seeing that your mapp.erl exports it, I suspect that the module mapp is not loaded.

How are you running the application? I suspect that you're not using a release tool like rebar3 or erlang.mk because usually the app files are inside src.

Upvotes: 2

Related Questions