"begin", "rescue",  "ensure", and the final "end" should all be at the same indentation level, i.e.:

begin
  ....
  ....
rescue
  ....
ensure
  ....
end