2323
2424
2525class BuildError (Exception ):
26- def __init__ (self , service ):
26+ def __init__ (self , service , reason ):
2727 self .service = service
28+ self .reason = reason
2829
2930
3031class CannotBeScaledError (Exception ):
@@ -307,7 +308,10 @@ def build(self):
307308 stream = True
308309 )
309310
310- all_events = stream_output (build_output , sys .stdout )
311+ try :
312+ all_events = stream_output (build_output , sys .stdout )
313+ except StreamOutputError , e :
314+ raise BuildError (self , unicode (e ))
311315
312316 image_id = None
313317
@@ -338,6 +342,10 @@ def can_be_scaled(self):
338342 return True
339343
340344
345+ class StreamOutputError (Exception ):
346+ pass
347+
348+
341349def stream_output (output , stream ):
342350 is_terminal = hasattr (stream , 'fileno' ) and os .isatty (stream .fileno ())
343351 all_events = []
@@ -362,11 +370,7 @@ def stream_output(output, stream):
362370 # move cursor up `diff` rows
363371 stream .write ("%c[%dA" % (27 , diff ))
364372
365- try :
366- print_output_event (event , stream , is_terminal )
367- except Exception :
368- stream .write (repr (event ) + "\n " )
369- raise
373+ print_output_event (event , stream , is_terminal )
370374
371375 if 'id' in event and is_terminal :
372376 # move cursor back down
@@ -378,7 +382,7 @@ def stream_output(output, stream):
378382
379383def print_output_event (event , stream , is_terminal ):
380384 if 'errorDetail' in event :
381- raise Exception (event ['errorDetail' ]['message' ])
385+ raise StreamOutputError (event ['errorDetail' ]['message' ])
382386
383387 terminator = ''
384388
0 commit comments