Skip to content

Commit de07e04

Browse files
committed
Show a nicer error when the env file doesn't exist
Closes #865 Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
1 parent dfc6206 commit de07e04

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

compose/service.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def __init__(self, name, client=None, project='default', links=None, external_li
9595
if 'image' in options and 'build' in options:
9696
raise ConfigError('Service %s has both an image and build path specified. A service can either be built to image or use an existing image, not both.' % name)
9797

98+
for filename in get_env_files(options):
99+
if not os.path.exists(filename):
100+
raise ConfigError("Couldn't find env file for service %s: %s" % (name, filename))
101+
98102
supported_options = DOCKER_CONFIG_KEYS + ['build', 'expose',
99103
'external_links']
100104

tests/unit/service_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ def test_env_from_multiple_files(self):
378378
{'ONE': '2', 'TWO': '1', 'THREE': '3', 'FOO': 'baz', 'DOO': 'dah'}
379379
)
380380

381+
def test_env_nonexistent_file(self):
382+
self.assertRaises(ConfigError, lambda: Service('foo', env_file='tests/fixtures/env/nonexistent.env'))
383+
384+
381385
@mock.patch.dict(os.environ)
382386
def test_resolve_environment_from_file(self):
383387
os.environ['FILE_DEF'] = 'E1'

0 commit comments

Comments
 (0)