Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add errors to ProjectError message, duplicate code #8063

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions compose/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ def update_labels(cls, value, labels):
raise ValueError("Invalid value for one_off: {}".format(repr(value)))


def raise_errors(errors):
"""
Raise a dict with error messages as values as a single ProjectError.
"""
if len(errors):
combined_errors = '\n'.join([
e.decode('utf-8') if isinstance(e, bytes) else e for e in errors.values()
])
raise ProjectError(combined_errors)


class Project:
"""
A collection of services.
Expand Down Expand Up @@ -510,11 +521,8 @@ def build_service(service):
'Building',
limit=5,
)
if len(errors):
combined_errors = '\n'.join([
e.decode('utf-8') if isinstance(e, bytes) else e for e in errors.values()
])
raise ProjectError(combined_errors)

raise_errors(errors)

else:
for service in services:
Expand Down Expand Up @@ -707,10 +715,8 @@ def get_deps(service):
None,
get_deps,
)
if errors:
raise ProjectError(
'Encountered errors while bringing up the project.'
)

raise_errors(errors)

return [
container
Expand Down Expand Up @@ -817,11 +823,8 @@ def pull_service(service):
log.warning('Some service image(s) must be built from source by running:\n'
' docker-compose build {}'
.format(' '.join(must_build)))
if len(errors):
combined_errors = '\n'.join([
e.decode('utf-8') if isinstance(e, bytes) else e for e in errors.values()
])
raise ProjectError(combined_errors)

raise_errors(errors)

def push(self, service_names=None, ignore_push_failures=False):
unique_images = set()
Expand Down