erlware / relx

Sane, simple release creation for Erlang
http://erlware.github.io/relx
Apache License 2.0
697 stars 232 forks source link

WIP: return error if env var is not set in vm.args or sys.config #764

Closed colrack closed 2 years ago

colrack commented 4 years ago

WIP fix #716 Simple implementation where in replace_os_vars fun I handle the case where the env var is not set and I replace the var with a marker named RELX_REPLACE_VAR_NOT_SET. Then before running the vm, I check if the marker is set in vm.args and sys.config. I that is the case, I stop the execution and print an error. As an example, if I have in my vm.args.src:

## Prevent epmd autostart
-start_epmd ${VM_START_EPMD}

and VM_START_EPMD is not set the error returned is

Error: an ENV variable in vm.args is not set: 
-start_epmd RELX_REPLACE_VAR_NOT_SET: {$VM_START_EPMD}

If I have in my sys.config.src

  {myapp, [
    {config_file_name, "${APP_CONFIG_FILE}"}
  ]

and APP_CONFIG_FILE is not set the error returned is

Error: an ENV variable in sys.config is not set: 
{config_file_name, "RELX_REPLACE_VAR_NOT_SET: {$APP_CONFIG_FILE}"}

This also fix the previous implementation where I check with slen > 1 && e=="" if the env var is set. This is not correct since an ENV var could be set to an empty string. The right way is to use builtin v in ENVIRON Let me know what if you think.