Skip to content

Commit 3abce42

Browse files
committed
Fix regression in handling of build errors
1 parent c78b952 commit 3abce42

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

fig/cli/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def main():
5252
log.error(e.explanation)
5353
sys.exit(1)
5454
except BuildError as e:
55-
log.error("Service '%s' failed to build." % e.service.name)
55+
log.error("Service '%s' failed to build: %s" % (e.service.name, e.reason))
5656
sys.exit(1)
5757

5858

fig/service.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323

2424

2525
class BuildError(Exception):
26-
def __init__(self, service):
26+
def __init__(self, service, reason):
2727
self.service = service
28+
self.reason = reason
2829

2930

3031
class 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+
341349
def 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

379383
def 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

Comments
 (0)