bad_return_from_state_function on "3.21 Complex State” of "OTP design principles"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
by
Reply | Threaded
Open this post in threaded view
|

bad_return_from_state_function on "3.21 Complex State” of "OTP design principles"

by
Hi,

"3.21 Complex State”

But I got exception below:
====================================
Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V9.0  (abort with ^G)
1> c(code_lock3).
{ok,code_lock3}
2> code_lock3:start_link([1,2,3], 4).
Locked
{ok,<0.67.0>}
3> code_lock3:button(1).
Locked
** exception exit: {bad_return_from_state_function,
                       {keep_state,
                           #{code => [1,2,3],remaining => [2,3]},
                           30000,
                           [{reply,
                                {<0.60.0>,#Ref<0.235851222.49545217.215838>},
                                ok}]}}
     in function  gen_statem:parse_event_result/8 (gen_statem.erl, line 1318)
     in call from gen_statem:loop_event/6 (gen_statem.erl, line 1015)
     in call from proc_lib:init_p_do_apply/3 (proc_lib.erl, line 247)
4> 
=ERROR REPORT==== 13-Dec-2017::15:46:09 ===
** State machine code_lock3 terminating
** Last event = {{call,{<0.60.0>,#Ref<0.235851222.49545217.215838>}},
                 {button,1}}
** When server state  = {{locked,4},#{}}
** Reason for termination = error:{bad_return_from_state_function,
                                   {keep_state,
                                    #{code => [1,2,3],remaining => [2,3]},
                                    30000,
                                    [{reply,
                                      {<0.60.0>,
                                       #Ref<0.235851222.49545217.215838>},
                                      ok}]}}
** Callback mode = [handle_event_function,state_enter]
** Stacktrace =
**  [{gen_statem,parse_event_result,8,[{file,"gen_statem.erl"},{line,1318}]},
     {gen_statem,loop_event,6,[{file,"gen_statem.erl"},{line,1015}]},
     {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
====================================

I think the problem is on this:
		[Digit|Rest] -> % Incomplete
		    {keep_state, Data#{remaining := Rest, 30000},
		     [{reply,From,ok}]};
Change code to below got the **exception
		[Digit|Rest] -> % Incomplete
		    {keep_state, Data#{remaining := Rest}, 30000,
		     [{reply,From,ok}]};

Actually, this is apparently wrong, since the map can not got “30000" in this case. I tried move “30000" out of the map, then the above exception occurs.
And, I also tried just remove the “30000”, and it works fine.
		[Digit|Rest] -> % Incomplete
		    {keep_state, Data#{remaining := Rest},
		     [{reply,From,ok}]};

My question is:
Is this a typo in the documentation?
Or
Am I missing something?

Thanks
by

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: bad_return_from_state_function on "3.21 Complex State” of "OTP design principles"

Guilherme Andrade
It seems to be a typo. I believe the intention is to set up an event timeout[1] of 30 seconds, but if so then the timeout interval should be bundled with the call reply  - "{reply,From,ok}" - in order to make it a part of the list of actions to perform.

Maybe the following will do the trick:

    {keep_state, Data#{remaining := Rest}, [30000, {reply,From,ok}]}

On 13 December 2017 at 08:01, by <[hidden email]> wrote:
Hi,

"3.21 Complex State”

But I got exception below:
====================================
Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V9.0  (abort with ^G)
1> c(code_lock3).
{ok,code_lock3}
2> code_lock3:start_link([1,2,3], 4).
Locked
{ok,<0.67.0>}
3> code_lock3:button(1).
Locked
** exception exit: {bad_return_from_state_function,
                       {keep_state,
                           #{code => [1,2,3],remaining => [2,3]},
                           30000,
                           [{reply,
                                {<0.60.0>,#Ref<0.235851222.49545217.215838>},
                                ok}]}}
     in function  gen_statem:parse_event_result/8 (gen_statem.erl, line 1318)
     in call from gen_statem:loop_event/6 (gen_statem.erl, line 1015)
     in call from proc_lib:init_p_do_apply/3 (proc_lib.erl, line 247)
4> 
=ERROR REPORT==== 13-Dec-2017::15:46:09 ===
** State machine code_lock3 terminating
** Last event = {{call,{<0.60.0>,#Ref<0.235851222.49545217.215838>}},
                 {button,1}}
** When server state  = {{locked,4},#{}}
** Reason for termination = error:{bad_return_from_state_function,
                                   {keep_state,
                                    #{code => [1,2,3],remaining => [2,3]},
                                    30000,
                                    [{reply,
                                      {<0.60.0>,
                                       #Ref<0.235851222.49545217.215838>},
                                      ok}]}}
** Callback mode = [handle_event_function,state_enter]
** Stacktrace =
**  [{gen_statem,parse_event_result,8,[{file,"gen_statem.erl"},{line,1318}]},
     {gen_statem,loop_event,6,[{file,"gen_statem.erl"},{line,1015}]},
     {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
====================================

I think the problem is on this:
		[Digit|Rest] -> % Incomplete
		    {keep_state, Data#{remaining := Rest, 30000},
		     [{reply,From,ok}]};
Change code to below got the **exception
		[Digit|Rest] -> % Incomplete
		    {keep_state, Data#{remaining := Rest}, 30000,
		     [{reply,From,ok}]};

Actually, this is apparently wrong, since the map can not got “30000" in this case. I tried move “30000" out of the map, then the above exception occurs.
And, I also tried just remove the “30000”, and it works fine.
		[Digit|Rest] -> % Incomplete
		    {keep_state, Data#{remaining := Rest},
		     [{reply,From,ok}]};

My question is:
Is this a typo in the documentation?
Or
Am I missing something?

Thanks
by

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions




--
Guilherme

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
by
Reply | Threaded
Open this post in threaded view
|

Re: bad_return_from_state_function on "3.21 Complex State” of "OTP design principles"

by
Yes, it works with:
                [Digit|Rest] ->
                    {keep_state, Data#{remaining := Rest},
                     [30000, {reply, From, ok}]};
Thanks
by
在 2017年12月13日,16:19,Guilherme Andrade <[hidden email]> 写道:

It seems to be a typo. I believe the intention is to set up an event timeout[1] of 30 seconds, but if so then the timeout interval should be bundled with the call reply  - "{reply,From,ok}" - in order to make it a part of the list of actions to perform.

Maybe the following will do the trick:

    {keep_state, Data#{remaining := Rest}, [30000, {reply,From,ok}]}

On 13 December 2017 at 08:01, by <[hidden email]> wrote:
Hi,

"3.21 Complex State”

But I got exception below:
====================================
Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V9.0  (abort with ^G)
1> c(code_lock3).
{ok,code_lock3}
2> code_lock3:start_link([1,2,3], 4).
Locked
{ok,<0.67.0>}
3> code_lock3:button(1).
Locked
** exception exit: {bad_return_from_state_function,
                       {keep_state,
                           #{code => [1,2,3],remaining => [2,3]},
                           30000,
                           [{reply,
                                {<0.60.0>,#Ref<0.235851222.49545217.215838>},
                                ok}]}}
     in function  gen_statem:parse_event_result/8 (gen_statem.erl, line 1318)
     in call from gen_statem:loop_event/6 (gen_statem.erl, line 1015)
     in call from proc_lib:init_p_do_apply/3 (proc_lib.erl, line 247)
4> 
=ERROR REPORT==== 13-Dec-2017::15:46:09 ===
** State machine code_lock3 terminating
** Last event = {{call,{<0.60.0>,#Ref<0.235851222.49545217.215838>}},
                 {button,1}}
** When server state  = {{locked,4},#{}}
** Reason for termination = error:{bad_return_from_state_function,
                                   {keep_state,
                                    #{code => [1,2,3],remaining => [2,3]},
                                    30000,
                                    [{reply,
                                      {<0.60.0>,
                                       #Ref<0.235851222.49545217.215838>},
                                      ok}]}}
** Callback mode = [handle_event_function,state_enter]
** Stacktrace =
**  [{gen_statem,parse_event_result,8,[{file,"gen_statem.erl"},{line,1318}]},
     {gen_statem,loop_event,6,[{file,"gen_statem.erl"},{line,1015}]},
     {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
====================================

I think the problem is on this:
		[Digit|Rest] -> % Incomplete
		    {keep_state, Data#{remaining := Rest, 30000},
		     [{reply,From,ok}]};
Change code to below got the **exception
		[Digit|Rest] -> % Incomplete
		    {keep_state, Data#{remaining := Rest}, 30000,
		     [{reply,From,ok}]};

Actually, this is apparently wrong, since the map can not got “30000" in this case. I tried move “30000" out of the map, then the above exception occurs.
And, I also tried just remove the “30000”, and it works fine.
		[Digit|Rest] -> % Incomplete
		    {keep_state, Data#{remaining := Rest},
		     [{reply,From,ok}]};

My question is:
Is this a typo in the documentation?
Or
Am I missing something?

Thanks
by

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions




--
Guilherme


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: bad_return_from_state_function on "3.21 Complex State” of "OTP design principles"

Raimo Niskanen-2
In reply to this post by Guilherme Andrade
On Wed, Dec 13, 2017 at 08:19:08AM +0000, Guilherme Andrade wrote:
> It seems to be a typo. I believe the intention is to set up an event
> timeout[1] of 30 seconds, but if so then the timeout interval should be
> bundled with the call reply  - "{reply,From,ok}" - in order to make it a
> part of the list of actions to perform.
>
> Maybe the following will do the trick:
>
>     {keep_state, Data#{remaining := Rest}, [30000, {reply,From,ok}]}

Yes - that fixes the typo.  Thank you!
/ Raimo Niskanen (I wrote that example)


>
> [1]: http://erlang.org/doc/man/gen_statem.html#type-event_timeout
>
> On 13 December 2017 at 08:01, by <[hidden email]> wrote:
>
> > Hi,
> >
> > I am trying the example on http://erlang.org/doc/
> > design_principles/statem.html#id77558
> > "3.21 Complex State”
> >
> > But I got exception below:
> > ====================================
> > Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:4:4] [ds:4:4:10]
> > [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
> >
> > Eshell V9.0  (abort with ^G)
> > 1> c(code_lock3).
> > {ok,code_lock3}
> > 2> code_lock3:start_link([1,2,3], 4).
> > Locked
> > {ok,<0.67.0>}
> > 3> code_lock3:button(1).
> > Locked
> > ** exception exit: {bad_return_from_state_function,
> >                        {keep_state,
> >                            #{code => [1,2,3],remaining => [2,3]},
> >                            30000,
> >                            [{reply,
> >                                 {<0.60.0>,#Ref<0.235851222.
> > 49545217.215838>},
> >                                 ok}]}}
> >      in function  gen_statem:parse_event_result/8 (gen_statem.erl, line
> > 1318)
> >      in call from gen_statem:loop_event/6 (gen_statem.erl, line 1015)
> >      in call from proc_lib:init_p_do_apply/3 (proc_lib.erl, line 247)
> > 4>
> > =ERROR REPORT==== 13-Dec-2017::15:46:09 ===
> > ** State machine code_lock3 terminating
> > ** Last event = {{call,{<0.60.0>,#Ref<0.235851222.49545217.215838>}},
> >                  {button,1}}
> > ** When server state  = {{locked,4},#{}}
> > ** Reason for termination = error:{bad_return_from_state_function,
> >                                    {keep_state,
> >                                     #{code => [1,2,3],remaining => [2,3]},
> >                                     30000,
> >                                     [{reply,
> >                                       {<0.60.0>,
> >                                        #Ref<0.235851222.49545217.215838>},
> >                                       ok}]}}
> > ** Callback mode = [handle_event_function,state_enter]
> > ** Stacktrace =
> > **  [{gen_statem,parse_event_result,8,[{file,"gen_statem.
> > erl"},{line,1318}]},
> >      {gen_statem,loop_event,6,[{file,"gen_statem.erl"},{line,1015}]},
> >      {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
> > ====================================
> >
> > I think the problem is on this:
> >
> > [Digit|Rest] -> % Incomplete
> >    {keep_state, Data#{remaining := Rest, 30000},
> >     [{reply,From,ok}]};
> >
> > Change code to below got the **exception
> >
> > [Digit|Rest] -> % Incomplete
> >    {keep_state, Data#{remaining := Rest}, 30000,
> >     [{reply,From,ok}]};
> >
> >
> > Actually, this is apparently wrong, since the map can not got “30000" in
> > this case. I tried move “30000" out of the map, then the above exception
> > occurs.
> > And, I also tried just remove the “30000”, and it works fine.
> >
> > [Digit|Rest] -> % Incomplete
> >    {keep_state, Data#{remaining := Rest},
> >     [{reply,From,ok}]};
> >
> >
> > My question is:
> > Is this a typo in the documentation?
> > Or
> > Am I missing something?
> >
> > Thanks
> > by
> >
> > _______________________________________________
> > erlang-questions mailing list
> > [hidden email]
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
> >
>
>
> --
> Guilherme

> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions


--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions