When using named function in configuration files, generating a release fails with the following error message.
Configuration file example:
prod.exs
config :asteroid, :token_store_refresh_token_before_store_callback,
&Asteroid.Utils.id_first_param/2
Error message:
$ MIX_ENV=prod mix release
Compiling 88 files (.ex)
Generated asteroid app
* assembling prod-0.1.0 on MIX_ENV=prod
* skipping runtime configuration (config/releases.exs not found)
** (Mix) Could not read configuration file. It likely has invalid configuration terms such as functions, references, and pids. Please make sure your configuration is made of numbers, atoms, strings, maps, tuples and lists. Reason: {22, :erl_parse, ['syntax error before: ', '\'.\'']}
(from https://github.com/elixir-lang/elixir/blob/master/lib/mix/lib/mix/release.ex#L368)
Named functions can used in configuration files.
When generating a release, named functions are not properly escaped. Example:
{token_store_refresh_token_before_store_callback, fun Elixir.Asteroid.Utils:id_first_param/2},
instead of:
{token_store_refresh_token_before_store_callback, fun 'Elixir.Asteroid.Utils':id_first_param/2},
Thanks, Erlang bug filled here! https://bugs.erlang.org/browse/ERL-1009
A fix has been merged in OTP, thanks for the report!
I am new to Elixir but I believe that this bug has not been killed:
O/S: Ubuntu 18.04.03 LTS
Elixir: 1.10.3
Erlang/OTP 23 [erts-11.0.1]
Phoenix: 1.5.1
Using the quantum scheduler I have the following anonymous function in the config.exs file:
config :infoxir, Infoxir.Cron,
jobs: [
{"*/5 6-22 * * *", fn -> Infoxir.Energy.refresh() end}
]
Whenever I start to build a release:
MIX_ENV=prod mix release
** (Mix) Could not read configuration file. It likely has invalid configuration terms such as functions, references, and pids. Please make sure your configuration is made of numbers, atoms, strings, maps, tuples and lists. Reason: {3, :erl_parse, ['syntax error before: ', 'Fun']}
Whenever I comment the anonymous function in config.exs, everything seems to work fine.
Anonymous functions can be used in the config without generating errors.
Looked up in the quantum docs (https://hexdocs.pm/quantum/configuration.html): Anonymous functions are currently not supported by certain release managers. But why?
@arnoldu only funs in the form &Mod.name/arity are supported, arbitrary anonymous functions aren't.
I found that Quantum supports an alternative form to specify which functions to call with:
{ModuleName, :function_name, [params]}
But that doesn't help me with the general problem, why I am restricted with the language in production environment which is not the case in development.