Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 709

Show
Ignore:
Timestamp:
02/20/05 10:51:10 (4 years ago)
Author:
david
Message:

Gives Rescues some Love #680

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/dependencies.rb

    r627 r709  
    7171            rescue LoadError 
    7272              raise LoadError, "Missing #{layer} #{dependency}.rb" 
     73            rescue Object => exception 
     74              exception.blame_file! "=> #{layer} #{dependency}.rb" 
     75              raise 
    7376            end 
    7477          end 
  • trunk/actionpack/lib/action_controller/templates/rescues/_request_and_response.rhtml

    r370 r709  
     1<% unless @exception.blamed_files.empty? %> 
     2  <a href="#" onclick="document.getElementById('blame_trace').style.display='block'; return false;">Show blamed files</a> 
     3  <pre id="blame_trace" style="display:none"><code><%=h @exception.describe_blame %></code></pre> 
     4<% end %> 
     5 
    16<% if defined?(Breakpoint) %> 
    27  <br /><br /> 
    3   <%= form_tag({:params => {}, :only_path => true}, "method" => @request.method) %> 
     8  <% begin %><%= form_tag({:params => {}, :only_path => true}, "method" => @request.method) %> 
    49    <input type="hidden" name="BP-RETRY" value="1" /> 
    510   
     
    1318    <input type="submit" value="Retry with Breakpoint" /> 
    1419  </form> 
     20  <% rescue Exception => e %> 
     21    <%=h "Couldn't render breakpoint link due to #{e.class} #{e.message}" %> 
     22  <% end %> 
    1523<% end %> 
    1624 
  • trunk/actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml

    r51 r709  
    77<h1> 
    88  <%=h @exception.class.to_s %> in 
    9   <%=h @request.parameters["controller"].capitalize %>#<%=h @request.parameters["action"] %> 
     9  <%=h (@request.parameters["controller"] || "<controller not set>").capitalize %>#<%=h @request.parameters["action"] || "<action not set>" %> 
    1010</h1> 
    1111<p><%=h Object.const_defined?(:RAILS_ROOT) ? @exception.message.gsub(RAILS_ROOT, "") : @exception.message %></p> 
  • trunk/activesupport/lib/active_support/dependencies.rb

    r624 r709  
    101101 
    102102    def load_file(file_path) 
    103       Controllers.module_eval(IO.read(file_path), file_path, 1) # Hard coded Controller line here!!! 
     103      begin 
     104        Controllers.module_eval(IO.read(file_path), file_path, 1) # Hard coded Controller line here!!! 
     105      rescue Object => exception 
     106        exception.blame_file! file_path 
     107        raise 
     108      end 
    104109    end 
    105110  end 
     
    126131    end 
    127132  end 
     133  def load(file, *extras) 
     134    begin super(file, *extras) 
     135    rescue Object => exception 
     136      exception.blame_file! file 
     137      raise 
     138    end 
     139  end 
     140  def require(file, *extras) 
     141    begin super(file, *extras) 
     142    rescue Object => exception 
     143      exception.blame_file! file 
     144      raise 
     145    end 
     146  end 
    128147end 
     148 
     149# Add file-blaming to exceptions 
     150class Exception 
     151  def blame_file!(file) 
     152    (@blamed_files ||= []).unshift file 
     153  end 
     154  attr_reader :blamed_files 
     155  def describe_blame 
     156    return nil if blamed_files.empty? 
     157    "This error occured while loading the following files:\n   #{blamed_files.join '\n   '}" 
     158  end 
     159end