Skip to content

Commit 83cccea

Browse files
committed
Handle env variable expansion errors better in config parsing
Also, change all instances of 'environmental variables' to 'environment variables', as that is the accepted terminology (which I didn't know up to this point!)
1 parent 8a8c680 commit 83cccea

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

scuba/config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,13 @@ def _get_volumes(data):
268268
def _expand_path(in_str):
269269
try:
270270
output = expand_env_vars(in_str)
271-
except (KeyError, ValueError):
271+
except KeyError as ke:
272272
# pylint: disable=raise-missing-from
273-
raise ConfigError("Unset environmental variable used in '{}'".format(in_str))
273+
raise ConfigError("Unset environment variable '{}' used in '{}'".format(ke.args[0], in_str))
274+
except ValueError as ve:
275+
raise ConfigError("Unable to expand string '{}' due to parsing "
276+
"errors".format(in_str)) from ve
277+
274278
return output
275279

276280
class ScubaVolume:

scuba/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def writeln(f, line):
8282
f.write(line + '\n')
8383

8484
def expand_env_vars(in_str):
85-
"""Expand environmental variables in a string
85+
"""Expand environment variables in a string
8686
8787
Can raise `KeyError` if a variable is referenced but not defined, similar to
8888
bash's nounset (set -u) option"""

tests/test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ def test_alias_volumes_set(self):
885885
assert v.options == ['z', 'ro']
886886

887887
def test_volumes_with_env_vars_simple(self):
888-
'''volume definitions can contain environmental variables'''
888+
'''volume definitions can contain environment variables'''
889889
os.environ["TEST_VOL_PATH"] = "/bar/baz"
890890
os.environ["TEST_VOL_PATH2"] = "/moo/doo"
891891
with open('.scuba.yml', 'w') as f:
@@ -906,7 +906,7 @@ def test_volumes_with_env_vars_simple(self):
906906
assert v.options == []
907907

908908
def test_volumes_with_env_vars_complex(self):
909-
'''complex volume definitions can contain environmental variables'''
909+
'''complex volume definitions can contain environment variables'''
910910
os.environ["TEST_HOME"] = "/home/testuser"
911911
os.environ["TEST_TMP"] = "/tmp"
912912
os.environ["TEST_MAIL"] = "/var/spool/mail/testuser"

0 commit comments

Comments
 (0)