pyaml_env icon indicating copy to clipboard operation
pyaml_env copied to clipboard

Add option for raising an error on missing ENV variable

Open Brias opened this issue 3 years ago • 3 comments

This PR implements #22 by adding a raise_if_missing option to the parse_config function.

If raise_if_missing is set to True, a ValueError is raised when the following conditions are met:

  1. The ENV variable is not set
  2. No default is set for the ENV variable

Example:

# ValueError is raised
data: !ENV ${NON_EXISTING_ENV}
# No ValueError is raised
data: !ENV ${NON_EXISTING_ENV:explicit_default_value}

For backwards compatibility, raise_if_missing is set to False by default.

Brias avatar Jan 04 '23 22:01 Brias

+1. If anything, should be the default behavior of raise_if_na. Sometimes you just don't have a default value.

maldoinc avatar Apr 29 '24 17:04 maldoinc

+1, very useful!

@mkaranasou - can we get this merged, once you have a spare moment?

pierec avatar Sep 24 '24 06:09 pierec