1
0
Эх сурвалжийг харах

Catchable error for parse failures in split_buffer

Signed-off-by: Joffrey F <[email protected]>
Joffrey F 9 жил өмнө
parent
commit
9abbe1b7f8

+ 2 - 1
compose/cli/main.py

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

+ 5 - 0
compose/errors.py

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

+ 6 - 4
compose/utils.py

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