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

Changeset 984

Show
Ignore:
Timestamp:
03/23/05 11:48:10 (3 years ago)
Author:
david
Message:

Improved error reporting especially around never shallowing exceptions. Debugging helpers should be much easier now #980 [Nicholas Seckar]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r980 r984  
    11*SVN* 
     2 
     3* Improved error reporting especially around never shallowing exceptions. Debugging helpers should be much easier now #980 [Nicholas Seckar] 
    24 
    35* Fixed Toggle.display in prototype.js #902 [Lucas Carlson] 
  • trunk/actionpack/lib/action_controller/dependencies.rb

    r780 r984  
    7272            begin 
    7373              require_dependency(dependency.to_s) 
    74             rescue LoadError 
    75               raise LoadError, "Missing #{layer} #{dependency}.rb" 
     74            rescue LoadError => e 
     75              raise LoadError.new("Missing #{layer} #{dependency}.rb").copy_blame!(e) 
    7676            rescue Object => exception 
    7777              exception.blame_file! "=> #{layer} #{dependency}.rb" 
     
    8484          inherited_without_model(child) 
    8585          return if child.controller_name == "application" # otherwise the ApplicationController in Rails will include itself 
     86          model_name = child.controller_name.singularize 
    8687          begin 
    87             child.model(child.controller_name.singularize) 
    88           rescue NameError, LoadError 
    89             # No neither singular or plural model available for this controller 
     88            require_dependency model_name 
     89            child.model model_name 
     90          rescue MissingSourceFile => e 
     91            raise unless e.path == model_name + '.rb' 
    9092          end 
    9193        end         
  • trunk/actionpack/lib/action_controller/helpers.rb

    r780 r984  
    5353              file_name  = arg.to_s.underscore + '_helper' 
    5454              class_name = file_name.camelize 
    55  
     55                 
    5656              begin 
    5757                require_dependency(file_name) 
    5858              rescue LoadError => load_error 
    5959                requiree = / -- (.*?)(\.rb)?$/.match(load_error).to_a[1] 
    60                 raise LoadError, requiree == file_name ? "Missing helper file helpers/#{file_name}.rb" : "Can't load file: #{requiree}" 
     60                msg = (requiree == file_name) ? "Missing helper file helpers/#{file_name}.rb" : "Can't load file: #{requiree}" 
     61                raise LoadError.new(msg).copy_blame!(load_error) 
    6162              end 
    6263 
     
    9192        def inherited(child) 
    9293          inherited_without_helper(child) 
    93           begin 
    94             child.helper(child.controller_path) 
    95           rescue ArgumentError, LoadError 
    96             # No default helper available for this controller 
     94          begin child.helper(child.controller_path) 
     95          rescue MissingSourceFile => e 
     96            raise unless e.path == "helpers/#{child.controller_path}_helper.rb" 
    9797          end 
    9898        end         
  • trunk/actionpack/lib/action_controller/routing.rb

    r976 r984  
    313313          require_dependency(route_file) if route_file 
    314314        rescue LoadError, ScriptError => e 
    315           raise RoutingError, "Cannot load config/routes.rb:\n    #{e.message}" 
     315          raise RoutingError.new("Cannot load config/routes.rb:\n    #{e.message}").copy_blame!(e) 
    316316        ensure # Ensure that there is at least one route: 
    317317          connect(':controller/:action/:id', :action => 'index', :id => nil) if @routes.empty? 
  • trunk/actionpack/lib/action_controller/templates/rescues/_request_and_response.rhtml

    r713 r984  
    1 <% if @exception.blamed_files && !@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> 
     1<% unless @exception.blamed_files.blank? %> 
     2  <% if (hide = @exception.blamed_files.length > 8) %> 
     3    <a href="#" onclick="document.getElementById('blame_trace').style.display='block'; return false;">Show blamed files</a> 
     4  <% end %> 
     5  <pre id="blame_trace" <%='style="display:none"' if hide %>><code><%=h @exception.describe_blame %></code></pre> 
    46<% end %> 
    57 
  • trunk/actionpack/lib/action_view/helpers/url_helper.rb

    r976 r984  
    2222      #   link_to "Delete this page", { :action => "destroy", :id => @page.id }, :confirm => "Are you sure?" 
    2323      def link_to(name, options = {}, html_options = nil, *parameters_for_method_reference) 
    24         html_options = (html_options || {}).stringify_keys 
     24        html_options = (html_options || {}).symbolize_keys 
    2525        convert_confirm_option_to_javascript!(html_options) 
    2626        if options.is_a?(String) 
  • trunk/actionwebservice/lib/action_web_service/container/action_controller_container.rb

    r800 r984  
    6565            rescue LoadError => load_error 
    6666              requiree = / -- (.*?)(\.rb)?$/.match(load_error).to_a[1] 
    67               raise LoadError, requiree == file_name ? "Missing API definition file in apis/#{file_name}.rb" : "Can't load file: #{requiree}" 
     67              msg = requiree == file_name ? "Missing API definition file in apis/#{file_name}.rb" : "Can't load file: #{requiree}" 
     68              raise LoadError.new(msg).copy_blame!(load_error) 
    6869            end 
    6970            klass = nil 
     
    8485          def inherited(child) 
    8586            inherited_without_api(child) 
    86             child.web_service_api(child.controller_path) 
    87           rescue Exception => e 
     87            begin child.web_service_api(child.controller_path) 
     88            rescue MissingSourceFile => e 
     89              raise unless e.path == "apis/#{child.controller_path}_api.rb" 
     90            end 
    8891          end 
    8992      end 
  • trunk/activesupport/lib/active_support/core_ext/object_and_class.rb

    r857 r984  
    2222    end 
    2323  end 
     24     
     25  def suppress(*exception_classes) 
     26    begin yield 
     27    rescue Exception => e 
     28      raise unless exception_classes.any? {|cls| e.kind_of? cls} 
     29    end 
     30  end 
    2431end 
    2532 
  • trunk/activesupport/lib/active_support/dependencies.rb

    r817 r984  
    2222      rescue LoadError 
    2323        raise unless swallow_load_errors 
    24       rescue Object => e 
    25         raise ScriptError, "#{e.message}" 
    2624      end 
    2725    end 
     
    180178        require_or_load(class_id.to_s.demodulize.underscore) 
    181179        if Object.const_defined?(class_id) then return Object.const_get(class_id) else raise LoadError end 
    182       rescue LoadError 
    183         raise NameError, "uninitialized constant #{class_id}" 
     180      rescue LoadError => e 
     181        raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e) 
    184182      end 
    185183    end 
     
    217215    "This error occured while loading the following files:\n   #{blamed_files.join "\n   "}" 
    218216  end 
     217 
     218  def copy_blame!(exc) 
     219    @blamed_files = exc.blamed_files.clone 
     220    self 
     221  end 
    219222end 
  • trunk/activesupport/test/core_ext/object_and_class_ext_test.rb

    r624 r984  
    2020  end 
    2121end 
     22 
     23class ObjectTests < Test::Unit::TestCase 
     24  def test_suppress_re_raises 
     25    assert_raises(LoadError) { suppress(ArgumentError) {raise LoadError} } 
     26  end 
     27  def test_suppress_supresses 
     28    suppress(ArgumentError) { raise ArgumentError } 
     29    suppress(LoadError) { raise LoadError } 
     30    suppress(LoadError, ArgumentError) { raise LoadError } 
     31    suppress(LoadError, ArgumentError) { raise ArgumentError } 
     32  end 
     33end