Change callback module as an action in get_statem:init/1

I get an error when I include the change_callback_module action as a result of get_statem:init/1. If I understand the documentation correctly, this action would be allowed at init/1, or not?
Point is, at the end of get_statem:init/1, I know which callback module is relevant and I want to make the switch to that callback module at that time
The error message I get is:
error:{bad_action_from_state_function, {change_callback_module, ....

I am using Erlang/OTP 22 [erts-10.5.4]

1 Like

Use state_enter callback mode and change the callback module in the next state’s enter clause. Use EventContentType as null to only match on the transition from init/1.

1 Like

Thanks, I’ll do that, however first I’ll have to upgrade from 22 to something more recent since gen_statem doesn’t support change_callback_module in that version. Since the documentation doesn’t mention the minimal version for this action, I was assuming it was in.

I did upgrade to 25.3 and now change_callback_module works as expected from init/1.

1 Like

The documentation actually states, in the reference manual for gen_statem, Description, the second Note; that this feature was added in OTP 22.3.

3 Likes