Fix bot_update to correctly handle exceptions

If an exception occurs during a try block which prevents a step from actually executing, then the finally block's attempt to access step.active_result will fail, and the original exception will be hidden behind a new exception from the recipe engine. This CL changes this behavior so that the original exception will always fire.

Review-Url: https://codereview.chromium.org/2175103002
changes/90/365990/1
martiniss 9 years ago committed by Commit bot
parent aa71dd9f50
commit 8697dfcf8b

@ -231,61 +231,67 @@ class BotUpdateApi(recipe_api.RecipeApi):
name += ' - %s' % suffix name += ' - %s' % suffix
# Ah hah! Now that everything is in place, lets run bot_update! # Ah hah! Now that everything is in place, lets run bot_update!
step_result = None
try: try:
# 87 and 88 are the 'patch failure' codes for patch download and patch # 87 and 88 are the 'patch failure' codes for patch download and patch
# apply, respectively. We don't actually use the error codes, and instead # apply, respectively. We don't actually use the error codes, and instead
# rely on emitted json to determine cause of failure. # rely on emitted json to determine cause of failure.
self(name, cmd, step_test_data=step_test_data, step_result = self(name, cmd, step_test_data=step_test_data,
ok_ret=(0, 87, 88), **kwargs) ok_ret=(0, 87, 88), **kwargs)
except self.m.step.StepFailure as f:
step_result = f.result
raise
finally: finally:
step_result = self.m.step.active_result if step_result:
self._last_returned_properties = step_result.json.output.get( self._last_returned_properties = step_result.json.output.get(
'properties', {}) 'properties', {})
if update_presentation: if update_presentation:
# Set properties such as got_revision. # Set properties such as got_revision.
for prop_name, prop_value in self.last_returned_properties.iteritems(): for prop_name, prop_value in (
step_result.presentation.properties[prop_name] = prop_value self.last_returned_properties.iteritems()):
# Add helpful step description in the step UI. step_result.presentation.properties[prop_name] = prop_value
if 'step_text' in step_result.json.output: # Add helpful step description in the step UI.
step_text = step_result.json.output['step_text'] if 'step_text' in step_result.json.output:
step_result.presentation.step_text = step_text step_text = step_result.json.output['step_text']
# Add log line output. step_result.presentation.step_text = step_text
if 'log_lines' in step_result.json.output: # Add log line output.
for log_name, log_lines in step_result.json.output['log_lines']: if 'log_lines' in step_result.json.output:
step_result.presentation.logs[log_name] = log_lines.splitlines() for log_name, log_lines in step_result.json.output['log_lines']:
step_result.presentation.logs[log_name] = log_lines.splitlines()
# Set the "checkout" path for the main solution.
# This is used by the Chromium module to figure out where to look for # Set the "checkout" path for the main solution.
# the checkout. # This is used by the Chromium module to figure out where to look for
# If there is a patch failure, emit another step that said things failed. # the checkout.
if step_result.json.output.get('patch_failure'): # If there is a patch failure, emit another step that said things
return_code = step_result.json.output.get('patch_apply_return_code') # failed.
if return_code == 3: if step_result.json.output.get('patch_failure'):
# This is download failure, hence an infra failure. return_code = step_result.json.output.get('patch_apply_return_code')
# Sadly, python.failing_step doesn't support kwargs. if return_code == 3:
self.m.python.inline( # This is download failure, hence an infra failure.
'Patch failure', # Sadly, python.failing_step doesn't support kwargs.
('import sys;' self.m.python.inline(
'print "Patch download failed. See bot_update step for details";' 'Patch failure',
'sys.exit(1)'), ('import sys;'
infra_step=True, 'print "Patch download failed. See bot_update step for'
step_test_data=lambda: self.m.raw_io.test_api.output( ' details";sys.exit(1)'),
'Patch download failed. See bot_update step for details', infra_step=True,
retcode=1) step_test_data=lambda: self.m.raw_io.test_api.output(
) 'Patch download failed. See bot_update step for details',
else: retcode=1)
# This is actual patch failure. )
self.m.tryserver.set_patch_failure_tryjob_result() else:
self.m.python.failing_step( # This is actual patch failure.
'Patch failure', 'Check the bot_update step for details') self.m.tryserver.set_patch_failure_tryjob_result()
self.m.python.failing_step(
# bot_update actually just sets root to be the folder name of the 'Patch failure', 'Check the bot_update step for details')
# first solution.
if step_result.json.output['did_run']: # bot_update actually just sets root to be the folder name of the
co_root = step_result.json.output['root'] # first solution.
cwd = kwargs.get('cwd', self.m.path['slave_build']) if step_result.json.output['did_run']:
if 'checkout' not in self.m.path: co_root = step_result.json.output['root']
self.m.path['checkout'] = cwd.join(*co_root.split(self.m.path.sep)) cwd = kwargs.get('cwd', self.m.path['slave_build'])
if 'checkout' not in self.m.path:
self.m.path['checkout'] = cwd.join(*co_root.split(self.m.path.sep))
return step_result return step_result

Loading…
Cancel
Save