Tried a more pythonic approach.
Alternative would have probably been:

if (failure.fail && failure.fail.stack && failure.fail.stack.screenshot && failure.fail.screenshot.dataURL)
  image = ...