l'essentiel est invisible pour les yeux

Monday, July 14, 2008

[Erlang tips] Sometimes to call mnesia:wait_for_tables is required

Hmm..,
I spent three hours for a Mnesia's strange error message, so write tips about error I'm confused. The tables on Mnesia often need a time to prepare their tables, and if tables aren't available, then we'll see storange error message.

% db_test.erl


write_db_test() ->
start(), % Start the server, mnesia and create required tables.
?assertMatch({ok, _}, mnesia:transaction(fun() -> #person{name="rakuto"})).

You may see the error is as follows:

{badmatch,{aborted,{no_exists,ready_queue}}}


It seems it need to call mnesia:wait_for_tables.

% db_test.erl

write_db_test() ->
start(), % Start the server, mnesia and create required tables.
mnesia:wait_for_tables([person], 3000),
?assertMatch({ok, _}, mnesia:transaction(fun() -> #person{name="rakuto"})).

I think that error message "{no_exists, table_name}" is not human friendly.