OTP error: bad_return

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

OTP error: bad_return

Ben Hsu
Hello,

I am trying to put my application under an OTP supervisor, and I'm seeing
an error message I don't understand when I start my application using
"application:start(app_name)".

The error says "bad_return", and I'm not sure if it means the tuple I'm
returning from init/1 is bad, or if my code is bad.

My supervisor code, which I took verbatim from the OTP book, looks like
this:

start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).

init([]) ->
    Server = {stats_gatherer, {stats_gatherer, start_link, []},
              permanent, 2000, worker, [stats_gatherer]},
Children = [Server],
RestartStrategy = {one_for_one, 0, 1},
{ok, RestartStrategy, Children}.


I tried running stats_gatherer:start_link() from the Erlang shell, and it
worked.

The error message is below. I would be grateful for any insight.

1> application:start(stats_app).
{error,
    {{error,
         {bad_return,
             {stats_sup,init,
                 {ok,{one_for_one,0,1},
                     [{stats_gatherer,
                          {stats_gatherer,start_link,[]},
                          permanent,2000,worker,
                          [stats_gatherer]}]}}}},
     {stats_app,start,[normal,[]]}}}

=INFO REPORT==== 14-Jun-2014::14:03:19 ===
    application: stats_app
    exited: {{error,
                 {bad_return,
                     {stats_sup,init,
                         {ok,{one_for_one,0,1},
                             [{stats_gatherer,
                                  {stats_gatherer,start_link,[]},
                                  permanent,2000,worker,
                                  [stats_gatherer]}]}}}},
             {stats_app,start,[normal,[]]}}
    type: temporary
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140614/623b694e/attachment.html>

Reply | Threaded
Open this post in threaded view
|

OTP error: bad_return

Francesco Mazzoli-2
It is the return value which is not what the supervisor expects. It should be

{ok, {RestartStrategy, ChildList}}, you are sending {ok, RestartStrategy, ChildList}

F



> On 14 Jun 2014, at 19:08, Ben Hsu <benhsu> wrote:
>
>
> Hello,
>
> I am trying to put my application under an OTP supervisor, and I'm seeing an error message I don't understand when I start my application using "application:start(app_name)".
>
> The error says "bad_return", and I'm not sure if it means the tuple I'm returning from init/1 is bad, or if my code is bad.
>
> My supervisor code, which I took verbatim from the OTP book, looks like this:
>
> start_link() ->
> supervisor:start_link({local, ?SERVER}, ?MODULE, []).
>
> init([]) ->
>     Server = {stats_gatherer, {stats_gatherer, start_link, []},
>               permanent, 2000, worker, [stats_gatherer]},
> Children = [Server],
> RestartStrategy = {one_for_one, 0, 1},
> {ok, RestartStrategy, Children}.
>
>
> I tried running stats_gatherer:start_link() from the Erlang shell, and it worked.
>
> The error message is below. I would be grateful for any insight.
>
> 1> application:start(stats_app).
> {error,
>     {{error,
>          {bad_return,
>              {stats_sup,init,
>                  {ok,{one_for_one,0,1},
>                      [{stats_gatherer,
>                           {stats_gatherer,start_link,[]},
>                           permanent,2000,worker,
>                           [stats_gatherer]}]}}}},
>      {stats_app,start,[normal,[]]}}}
>
> =INFO REPORT==== 14-Jun-2014::14:03:19 ===
>     application: stats_app
>     exited: {{error,
>                  {bad_return,
>                      {stats_sup,init,
>                          {ok,{one_for_one,0,1},
>                              [{stats_gatherer,
>                                   {stats_gatherer,start_link,[]},
>                                   permanent,2000,worker,
>                                   [stats_gatherer]}]}}}},
>              {stats_app,start,[normal,[]]}}
>     type: temporary
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140614/1db97d58/attachment.html>