diff --git a/recipe_modules/tryserver/api.py b/recipe_modules/tryserver/api.py index 48a2edd1f5..4e60181d12 100644 --- a/recipe_modules/tryserver/api.py +++ b/recipe_modules/tryserver/api.py @@ -284,14 +284,17 @@ class TryserverApi(recipe_api.RecipeApi): except self.m.step.StepFailure as e: self.add_failure_reason(e.reason) - failure_hash = hashlib.sha1() - failure_hash.update(self.m.json.dumps(self._failure_reasons)) - - step_result = self.m.step.active_result - step_result.presentation.properties['failure_hash'] = \ - failure_hash.hexdigest() - - raise + try: + step_result = self.m.step.active_result + except ValueError: + step_result = None + if step_result: + failure_hash = hashlib.sha1() + failure_hash.update(self.m.json.dumps(self._failure_reasons)) + step_result.presentation.properties['failure_hash'] = ( + failure_hash.hexdigest()) + + raise e def get_footers(self, patch_text=None): """Retrieves footers from the patch description. diff --git a/recipe_modules/tryserver/example.expected/set_failure_hash_with_no_steps.json b/recipe_modules/tryserver/example.expected/set_failure_hash_with_no_steps.json new file mode 100644 index 0000000000..edb74118c5 --- /dev/null +++ b/recipe_modules/tryserver/example.expected/set_failure_hash_with_no_steps.json @@ -0,0 +1,8 @@ +[ + { + "name": "$result", + "reason": "boom!", + "recipe_result": null, + "status_code": 1 + } +] \ No newline at end of file diff --git a/recipe_modules/tryserver/example.py b/recipe_modules/tryserver/example.py index 69a091781f..f73c41a5b5 100644 --- a/recipe_modules/tryserver/example.py +++ b/recipe_modules/tryserver/example.py @@ -15,6 +15,10 @@ DEPS = [ def RunSteps(api): + if api.properties.get('set_failure_hash_with_no_steps'): + with api.tryserver.set_failure_hash(): + raise api.step.StepFailure('boom!') + api.path['checkout'] = api.path['start_dir'] if api.properties.get('patch_text'): api.step('patch_text test', [ @@ -106,3 +110,6 @@ def GenTests(api): 'parse description (2)', api.json.output({'Foo': ['bar']})) ) + + yield (api.test('set_failure_hash_with_no_steps') + + api.properties(set_failure_hash_with_no_steps=True)) \ No newline at end of file