Catchable error for parse failures in split_buffer

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2016-08-01 11:50:57 -07:00
parent 1c07d6453f
commit bd7db570bd
3 changed files with 13 additions and 5 deletions

View File

@ -23,6 +23,7 @@ from ..config.environment import Environment
from ..config.serialize import serialize_config from ..config.serialize import serialize_config
from ..const import DEFAULT_TIMEOUT from ..const import DEFAULT_TIMEOUT
from ..const import IS_WINDOWS_PLATFORM from ..const import IS_WINDOWS_PLATFORM
from ..errors import StreamParseError
from ..progress_stream import StreamOutputError from ..progress_stream import StreamOutputError
from ..project import NoSuchService from ..project import NoSuchService
from ..project import OneOffFilter from ..project import OneOffFilter
@ -75,7 +76,7 @@ def main():
except NeedsBuildError as e: except NeedsBuildError as e:
log.error("Service '%s' needs to be built, but --no-build was passed." % e.service.name) log.error("Service '%s' needs to be built, but --no-build was passed." % e.service.name)
sys.exit(1) sys.exit(1)
except errors.ConnectionError: except (errors.ConnectionError, StreamParseError):
sys.exit(1) sys.exit(1)

View File

@ -5,3 +5,8 @@ from __future__ import unicode_literals
class OperationFailedError(Exception): class OperationFailedError(Exception):
def __init__(self, reason): def __init__(self, reason):
self.msg = reason self.msg = reason
class StreamParseError(RuntimeError):
def __init__(self, reason):
self.msg = reason

View File

@ -9,6 +9,8 @@ import logging
import six import six
from .errors import StreamParseError
json_decoder = json.JSONDecoder() json_decoder = json.JSONDecoder()
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -64,12 +66,12 @@ def split_buffer(stream, splitter=None, decoder=lambda a: a):
if buffered: if buffered:
try: try:
yield decoder(buffered) yield decoder(buffered)
except ValueError: except Exception as e:
log.error( log.error(
'Compose tried parsing the following chunk as a JSON object, ' 'Compose tried decoding the following data chunk, but failed:'
'but failed:\n%s' % repr(buffered) '\n%s' % repr(buffered)
) )
raise raise StreamParseError(e)
def json_splitter(buffer): def json_splitter(buffer):