Elixir: Named functions not properly escaped when written to sys.config

Created on 20 Jul 2019  路  5Comments  路  Source: elixir-lang/elixir

Environment

  • Elixir & Erlang/OTP versions (elixir --version): 1.9.0 / OTP21
  • Operating system: Linux

Current behavior

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)

Expected behavior

Named functions can used in configuration files.

Root cause

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},
Erlang bug

All 5 comments

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:

Environment

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}
]

Current behaviour

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.

Expected behaviour

Anonymous functions can be used in the config without generating errors.

Additional hint

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LucianaMarques picture LucianaMarques  路  3Comments

GianFF picture GianFF  路  3Comments

coryodaniel picture coryodaniel  路  3Comments

DEvil0000 picture DEvil0000  路  3Comments

cmeiklejohn picture cmeiklejohn  路  3Comments