[erlang-questions] Need some OTP design advice

Colin Z theczintheroc2007@REDACTED
Fri Jul 11 21:19:44 CEST 2008

I need some advice on part of an application I'm writing.

Basically I've got a gen_server that is responsible for processing command
records sent to it via casts.

It just uses an mnesia DB to map command codes to logic modules (so, it's
kind of like a scripting system).

I'm running into problems when there's a typo in the DB (ie: the module
specified in the DB doesn't actually exist) or when there's an error in the
logic module. It will cause my gen_server to crash. If it crashes too often
it'll bring down the application obviously.

handle_cast(  {queue_command, ?CMD_VAR}, State ) ->

    Command = mnesia:dirty_read(?STATE.commandDB,

    case Command of
        [] ->
            io:fwrite("Could not find command `~p`~n",[?CMD.command]),
        [#command{module=Module}] ->
            case gen_command:validate(Module, ?CMD_VAR) of
                ok ->
                    gen_command:do(Module, ?CMD_VAR),
                denied ->
    {noreply, State}

If it finds the command code in the DB it will call the logic module's
validate() method to see if it's allowed, then calls do().  (I'm doing some
magic with the macros there, but it's just convenience for working with

The gen_command module just does this:

do(CallbackModule, ?CMD_VAR) ->

Should I be doing a try...catch in gen_command to keep the gen_server from
crashing, or is my design just way off to begin with? Or maybe I should be
letting the server crash and just change the supervision tree so it can
crash as many times as it wants?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080711/dffebc60/attachment.htm>

More information about the erlang-questions mailing list