Skip to content

Commit

Permalink
Get rid of a rescue nil
Browse files Browse the repository at this point in the history
From the commit (cfdf97d) which introduced it:

-        begin
-          data = ::IO.read(file).split(/^__END__$/)[1]
-        rescue
-          data = nil
-        end
+        app, data =
+          ::IO.read(file).split(/^__END__$/, 2) rescue nil

The rescue block in the cfdf97d^ tree was introduced in b88c0f5
because of #201. I am not 100% sure that rescueing Errno::ENOENT
is enough, though. Please let me know if it is not.
  • Loading branch information
sr committed Dec 26, 2009
1 parent 9208150 commit e340d18
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/sinatra/base.rb
Expand Up @@ -680,8 +680,13 @@ def layout(name=:layout, &block)
# when no file is specified.
def use_in_file_templates!(file=nil)
file ||= caller_files.first
app, data =
::IO.read(file).split(/^__END__$/, 2) rescue nil

begin
app, data =
::IO.read(file).split(/^__END__$/, 2)
rescue Errno::ENOENT
app, data = nil
end

if data
data.gsub!(/\r\n/, "\n")
Expand Down

0 comments on commit e340d18

Please sign in to comment.