From 9d9b8657966a574ff4ec30390985606227ea6e14 Mon Sep 17 00:00:00 2001 From: Mazz Mosley Date: Thu, 16 Jul 2015 16:07:30 +0100 Subject: [PATCH] Add in error handling Signed-off-by: Mazz Mosley --- compose/utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/compose/utils.py b/compose/utils.py index 5ffe7b707..c3316ccda 100644 --- a/compose/utils.py +++ b/compose/utils.py @@ -5,6 +5,7 @@ import logging import os import sys +from docker.errors import APIError import concurrent.futures from .const import DEFAULT_MAX_WORKERS @@ -20,12 +21,16 @@ def parallel_execute(command, containers, doing_msg, done_msg, **options): max_workers = os.environ.get('COMPOSE_MAX_WORKERS', DEFAULT_MAX_WORKERS) stream = codecs.getwriter('utf-8')(sys.stdout) lines = [] + errors = {} for container in containers: write_out_msg(stream, lines, container.name, doing_msg) def container_command_execute(container, command, **options): - return getattr(container, command)(**options) + try: + getattr(container, command)(**options) + except APIError as e: + errors[container.name] = e.explanation with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor: future_container = { @@ -41,6 +46,10 @@ def parallel_execute(command, containers, doing_msg, done_msg, **options): container = future_container[future] write_out_msg(stream, lines, container.name, done_msg) + if errors: + for container in errors: + stream.write("ERROR: for {} {} \n".format(container, errors[container])) + def write_out_msg(stream, lines, container_name, msg): """