<div dir="ltr"><div>Hi Raimo,<br><br></div><div>I'm looking forward to that particular error being more understandable in a future release. It is too small to patch for.<br><br></div><div>The other day I was trying to capture a somewhat elaborate state machine in a gen_statem and I hadn't read the manual well enough, so I thought that I could do some nifty checking in the enter clause and decide if another state was more suited to do the job. But with state_enter you cannot change state in the enter clause. It is clearly written din the manual, but... you know... blush.<br><br></div><div>However, the error message doesn't point you to this fundamental rule:<br></div><div><span style="font-family:monospace"><br>** Last event = {internal,init_state}<br>** When server state = {starting,happy}<br>** Reason for termination = error:{bad_return_from_state_function,<br> {next_state,creating,happy}}<br>** Callback mode = [state_functions,state_enter]</span><br></div><div><br></div><div>It would be nice if it said something about not changing state when entering.<br><br></div><div>Same kind of issue when adding next_event in a state enter:<br><span style="font-family:monospace"><br>** Reason for termination = error:{bad_action_from_state_</span><span style="font-family:monospace">function,<br> </span><span style="font-family:monospace"> {next_event,internal,jump}}</span><br><br></div><div>Maybe the error should be {dont_add_next_event_in_enter_read_the_manual_dude, ...} or something to that effect!<br><br></div><div>And when you misspell next_state you get this:<br><br><span style="font-family:monospace">** Reason for termination = error:{bad_return_from_state_function,<br> {next_stete,running,happy,<br> {next_event,internal,jump}}}</span><br><br></div><div>It would be nice if it said what it could not like.<br></div><div><br></div><div>I have not looked in the gen_statem code, but I am pretty sure that the checks would allow more details in the error messages. The information must be at hand when it errors out.<br><br></div><div>Cheers,<br></div><div>Torben<br></div><div><br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, May 16, 2018 at 8:52 AM Raimo Niskanen <<a href="mailto:raimo%2Berlang-questions@erix.ericsson.se" target="_blank">raimo+erlang-questions@erix.ericsson.se</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, May 15, 2018 at 10:59:50PM +0200, Torben Hoffmann wrote:<br>
> Hi,<br>
> Would it be possible to add some text to the gen_statem docs that this<br>
> message usually means you have messed up one of the actions?<br>
> It wasn't obvious to me before I googled it and then it was a matter of<br>
> chasing down all my actions.<br>
> Somehow I find the error messages of gen_statem harder to work with than<br>
> gen_fsm, which is a pity since gen_statem is so much easier to work with in<br>
> terms of design flexibility and easy to raed code.<br>
> <br>
> Cheers,<br>
> Torben<br>
<br>
The message in this case:<br>
Context: child_terminated Reason:<br>
{{badrecord,trans_opts},<br>
[{gen_statem,loop_event_actions_list,10,<br>
[{file,"gen_statem.erl"},{line,1210}]},<br>
{proc_lib,init_p_do_apply,3,<br>
[{file,"proc_lib.erl"},{line,247}]}]}<br>
<br>
I classify this as a bug, but not severe enough to merit a patch on the 20.3<br>
release. What the code was trying to do but crashed instead was to<br>
terminate with error:{bad_action_from_state_function,Action} in a regular<br>
Error Report.<br>
<br>
The intention is that gen_statem should pinpoint bad actions fairly<br>
precisely. That crash is fixed in 20.0-rc1 and later so it will terminate<br>
as intended.<br>
<br>
I agree that the OP:s crash is not a good error message for end users, but<br>
it was a good one for me since it was precise for me to fix the crash.<br>
<br>
Do you have any suggestions about improving correct error messages from<br>
gen_statem, or can you exemplify some that you find hard to understand?<br>
In comparison with gen_fsm, if you like.<br>
<br>
Best Regards<br>
/ Raimo<br>
<br>
<br>
> <br>
> <br>
> On Tue, May 15, 2018 at 8:23 AM getonga <<a href="mailto:getonga@qq.com" target="_blank">getonga@qq.com</a>> wrote:<br>
> <br>
> > Thanks, I recheck my source code, and I found the error reason. Thanks for<br>
> > your time.<br>
> > _______________________________________________<br>
> > erlang-questions mailing list<br>
> > <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
> > <a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
> ><br>
> -- <br>
> <a href="https://www.linkedin.com/in/torbenhoffmann/" rel="noreferrer" target="_blank">https://www.linkedin.com/in/torbenhoffmann/</a><br>
<br>
> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
<br>
-- <br>
<br>
/ Raimo Niskanen, Erlang/OTP, Ericsson AB<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><a href="https://www.linkedin.com/in/torbenhoffmann/">https://www.linkedin.com/in/torbenhoffmann/</a><br></div></div>