[erlang-questions] io:format, gen_fsm, eunit

nic nic@REDACTED
Wed Sep 5 07:19:08 CEST 2007

Hi all

I'm yet another of the Erlang total newbies, so please be patient with what is probably a 
really dumb question.

I've created a very basic gen_fsm-based state machine which works fine in the shell. I 
intend to add states and actions to it as my application evolves. At the moment, it prints 
a message (using io:format) at each state transition. I'm using eunit to make sure I don't 
break anything as I add to the FSM (and partly for the experience of using eunit).

My first test creates an FSM, sends a single event (which causes a transition message to 
be printed) then stops the FSM. eunit says the test works OK, but I get an error message 
printed which _looks_ really ugly:

=ERROR REPORT==== 5-Sep-2007::16:54:37 ===
** State machine dll_1 terminating
** Last event in was init
** When State == in_reset
**      Data  == {state,0,undefined,undefined}
** Reason for termination =
** {ebadf,[{io,format,
                 "in_reset Event: ~p, State: ~p~n",
   Test successful.

I think I can see what's going on: the io:format's file descriptor has disappeared (been 
closed) before the write has finished, presumably because the gen_fsm process that opened 
it has been stopped.

The test is successful, so I could just live with the ugly error message, but I can 
imagine that if there were a few of these it would be really easy to miss some useful 
error reports amongst all the noise. It's a bit like ignoring compiler warnings: I've 
always found it pays to make things compile clean.

So (finally) is it something to do with the way I'm setting up the test, or is there a 
cunning (or obvious!) way around it, or should I just live with it, or what?


Nic C-L

More information about the erlang-questions mailing list