##// END OF EJS Templates
env-vars: provide better feedback when formatting an env variable fails.
dan -
r3366:c2838a63 default
parent child Browse files
Show More
@@ -708,18 +708,29 b' def _string_setting(settings, name, defa'
708 708
709 709
710 710 def _substitute_values(mapping, substitutions):
711 result = {}
711 712
712 713 try:
713 result = {
714 for key, value in mapping.items():
715 # initialize without substitution first
716 result[key] = value
717
714 718 # Note: Cannot use regular replacements, since they would clash
715 719 # with the implementation of ConfigParser. Using "format" instead.
716 key: value.format(**substitutions)
717 for key, value in mapping.items()
718 }
719 except KeyError as e:
720 raise ValueError(
721 'Failed to substitute env variable: {}. '
722 'Make sure you have specified this env variable without ENV_ prefix'.format(e))
720 try:
721 result[key] = value.format(**substitutions)
722 except KeyError as e:
723 env_var = '{}'.format(e.args[0])
724
725 msg = 'Failed to substitute: `{key}={{{var}}}` with environment entry. ' \
726 'Make sure your environment has {var} set, or remove this ' \
727 'variable from config file'.format(key=key, var=env_var)
728
729 if env_var.startswith('ENV_'):
730 raise ValueError(msg)
731 else:
732 log.warning(msg)
733
723 734 except ValueError as e:
724 735 log.warning('Failed to substitute ENV variable: %s', e)
725 736 result = mapping
General Comments 0
You need to be logged in to leave comments. Login now