<div dir="ltr"><div><div><div>Those improvements are really good.<br><br></div>I can live without AI in the OTP libs ;-)<br><br></div>Cheers,<br></div>Torben<br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, May 16, 2018 at 12:13 PM Raimo Niskanen <<a href="mailto:raimo%2Berlang-questions@erix.ericsson.se">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 Wed, May 16, 2018 at 10:39:36AM +0200, Torben Hoffmann wrote:<br>
> Hi Raimo,<br>
> <br>
> I'm looking forward to that particular error being more understandable in a<br>
> future release. It is too small to patch for.<br>
> <br>
> The other day I was trying to capture a somewhat elaborate state machine in<br>
> a gen_statem and I hadn't read the manual well enough, so I thought that I<br>
> could do some nifty checking in the enter clause and decide if another<br>
> state was more suited to do the job. But with state_enter you cannot change<br>
> state in the enter clause. It is clearly written din the manual, but... you<br>
> know... blush.<br>
> <br>
> However, the error message doesn't point you to this fundamental rule:<br>
> <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]<br>
> <br>
> It would be nice if it said something about not changing state when<br>
> entering.<br>
<br>
That one was changed to<br>
error:{bad_state_enter_return_from_state_function,<br>
{next_state,creating,happy}}<br>
in commit ea1963553ffb06eb1bda636f328718f91136ed9c on 'master'<br>
<br>
I hope that is not too subtle - I wanted to stick to the format.<br>
At least it indicates state_enter and state function.<br>
<br>
<br>
> <br>
> Same kind of issue when adding next_event in a state enter:<br>
> <br>
> ** Reason for termination = error:{bad_action_from_state_function,<br>
> {next_event,internal,jump}}<br>
> <br>
> Maybe the error should be<br>
> {dont_add_next_event_in_enter_read_the_manual_dude, ...} or something to<br>
> that effect!<br>
> <br>
<br>
That one was changed to<br>
error:{bad_state_enter_action_from_state_function,<br>
{next_event,internal,jump}}<br>
in the same commit.<br>
<br>
<br>
> And when you misspell next_state you get this:<br>
> <br>
> ** Reason for termination = error:{bad_return_from_state_function,<br>
> {next_stete,running,happy,<br>
> {next_event,internal,jump}}}<br>
> <br>
> It would be nice if it said what it could not like.<br>
<br>
In this case you return a tuple with a tag that is not recognized, and it<br>
would take some artificial intelligence to figure out that it most likely<br>
should be next_state that the user attempted.<br>
<br>
The tuple does not match any of the allowed patterns, simply, so it is<br>
a bad return value. Difficult to do anything smarter.<br>
<br>
<br>
Best regards<br>
/ Raimo<br>
<br>
<br>
> <br>
> I have not looked in the gen_statem code, but I am pretty sure that the<br>
> checks would allow more details in the error messages. The information must<br>
> be at hand when it errors out.<br>
> <br>
> Cheers,<br>
> Torben<br>
> <br>
> <br>
> On Wed, May 16, 2018 at 8:52 AM Raimo Niskanen <<br>
> <a href="mailto:raimo%2Berlang-questions@erix.ericsson.se" target="_blank">raimo+erlang-questions@erix.ericsson.se</a>> wrote:<br>
> <br>
> > 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<br>
> > 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<br>
> > 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<br>
> > for<br>
> > > > your time.<br>
> > > --<br>
> > > <a href="https://www.linkedin.com/in/torbenhoffmann/" rel="noreferrer" target="_blank">https://www.linkedin.com/in/torbenhoffmann/</a><br>
> ><br>
> > --<br>
> ><br>
> > / Raimo Niskanen, Erlang/OTP, Ericsson AB<br>
> -- <br>
> <a href="https://www.linkedin.com/in/torbenhoffmann/" rel="noreferrer" target="_blank">https://www.linkedin.com/in/torbenhoffmann/</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>-- <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>