[erlang-questions] application startup failure?

Hynek Vychodil <>
Thu Nov 25 13:45:43 CET 2010


Why not just do pattern match to return value from mnesia call? I
think it is The Idiomatic Erlang Way. Let's it crash.

start(Type, StartArgs) ->
  {atomic, ok} = {error, ohmygod}, %% return value from any call
  {ok, []}.

1> application:start(foo).

=CRASH REPORT==== 25-Nov-2010::13:41:51 ===
  crasher:
    initial call: application_master:init/4
    pid: <0.58.0>
    registered_name: []
    exception exit: {bad_return,
                        {{foo,start,[normal,[]]},
                         {'EXIT',
                             {{badmatch,{error,ohmygod}},
                              [{foo,start,2},
                               {application_master,start_it_old,4}]}}}}
      in function  application_master:init/4
    ancestors: [<0.57.0>]
    messages: [{'EXIT',<0.59.0>,normal}]
    links: [<0.57.0>,<0.6.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 377
    stack_size: 24
    reductions: 105
  neighbours:

=INFO REPORT==== 25-Nov-2010::13:41:51 ===
    application: foo
    exited: {bad_return,{{foo,start,[normal,[]]},
                         {'EXIT',{{badmatch,{error,ohmygod}},
                                  [{foo,start,2},
                                   {application_master,start_it_old,4}]}}}}
    type: temporary
{error,{bad_return,{{foo,start,[normal,[]]},
                    {'EXIT',{{badmatch,{error,ohmygod}},

[{foo,start,2},{application_master,start_it_old,4}]}}}}}

On Tue, Nov 23, 2010 at 5:11 AM, Scott Lystig Fritchie
<> wrote:
> Andy Kriger <> wrote:
>
> ak> Or maybe there's a better way to handle this situation?
>
> Andy, would it be awful to simply call error_logger:error_msg() or
> similar in your app's init() function before it returns {error, Reason}?
>
> If you have the sasl application already running, then you should also
> get both a crasher report and an info report that contain the returned
> reason.  Code follows the messages.  Comparing info reports, it looks
> like your app's Reason term really is 'shutdown'?  {shrug}
>
> -Scott
>
> 1> application:start(sasl).
> ok
> 2> application:start(foo).
> {error,{yofoo,{foo,start,[normal,[]]}}}
>
> =ERROR REPORT==== 22-Nov-2010::22:05:20 ===
> foo:start type normal args []
>
> =CRASH REPORT==== 22-Nov-2010::22:05:20 ===
>  crasher:
>    initial call: application_master:init/4
>    pid: <0.47.0>
>    registered_name: []
>    exception exit: {yofoo,{foo,start,[normal,[]]}}
>      in function  application_master:init/4
>    ancestors: [<0.46.0>]
>    messages: [{'EXIT',<0.48.0>,normal}]
>    links: [<0.46.0>,<0.6.0>]
>    dictionary: []
>    trap_exit: true
>    status: running
>    heap_size: 233
>    stack_size: 24
>    reductions: 102
>  neighbours:
>
> =INFO REPORT==== 22-Nov-2010::22:05:21 ===
>    application: foo
>    exited: {yofoo,{foo,start,[normal,[]]}}
>    type: temporary
>
> --- snip --- snip --- snip --- snip --- snip --- snip --- snip ---
>
> %% foo.erl
>
> -module(foo).
> -author('').
>
> -behaviour(application).
>
> -export([start/2, stop/1]).
>
> start(Type, StartArgs) ->
>    error_logger:error_msg("~s:start type ~p args ~p\n", [?MODULE, Type,
>    StartArgs]),
>    {error, yofoo}.
>
> stop(State) ->
>    ok.
>
> --- snip --- snip --- snip --- snip --- snip --- snip --- snip ---
>
> %% foo.app
>
> {application, foo,
>  [{description, "foo app"},
>  {vsn, "99"},
>  {modules, [ foo
>              ]},
>  {registered, []},
>  {applications, [kernel,
>                  stdlib,
>                  sasl]},
>  {mod, { foo, []}},
>  {env, []}
> ]}.
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>



-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill
your boss.  Be a data hero!
Try GoodData now for free: www.gooddata.com


More information about the erlang-questions mailing list