From 3697df1dd2be6e51867bea4d6089f01f8f204f3c Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 23 Mar 2005 11:48:10 +0000 Subject: Improved error reporting especially around never shallowing exceptions. Debugging helpers should be much easier now #980 [Nicholas Seckar] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@984 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/dependencies.rb | 14 ++++++++------ actionpack/lib/action_controller/helpers.rb | 12 ++++++------ actionpack/lib/action_controller/routing.rb | 2 +- .../templates/rescues/_request_and_response.rhtml | 8 +++++--- 4 files changed, 20 insertions(+), 16 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/dependencies.rb b/actionpack/lib/action_controller/dependencies.rb index 1deaf0ce4b..7fb72417c0 100644 --- a/actionpack/lib/action_controller/dependencies.rb +++ b/actionpack/lib/action_controller/dependencies.rb @@ -71,8 +71,8 @@ module ActionController #:nodoc: dependencies.flatten.each do |dependency| begin require_dependency(dependency.to_s) - rescue LoadError - raise LoadError, "Missing #{layer} #{dependency}.rb" + rescue LoadError => e + raise LoadError.new("Missing #{layer} #{dependency}.rb").copy_blame!(e) rescue Object => exception exception.blame_file! "=> #{layer} #{dependency}.rb" raise @@ -83,12 +83,14 @@ module ActionController #:nodoc: def inherited(child) inherited_without_model(child) return if child.controller_name == "application" # otherwise the ApplicationController in Rails will include itself + model_name = child.controller_name.singularize begin - child.model(child.controller_name.singularize) - rescue NameError, LoadError - # No neither singular or plural model available for this controller + require_dependency model_name + child.model model_name + rescue MissingSourceFile => e + raise unless e.path == model_name + '.rb' end end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/helpers.rb b/actionpack/lib/action_controller/helpers.rb index fcfd45a507..1db8a3ceba 100644 --- a/actionpack/lib/action_controller/helpers.rb +++ b/actionpack/lib/action_controller/helpers.rb @@ -52,12 +52,13 @@ module ActionController #:nodoc: when String, Symbol file_name = arg.to_s.underscore + '_helper' class_name = file_name.camelize - + begin require_dependency(file_name) rescue LoadError => load_error requiree = / -- (.*?)(\.rb)?$/.match(load_error).to_a[1] - raise LoadError, requiree == file_name ? "Missing helper file helpers/#{file_name}.rb" : "Can't load file: #{requiree}" + msg = (requiree == file_name) ? "Missing helper file helpers/#{file_name}.rb" : "Can't load file: #{requiree}" + raise LoadError.new(msg).copy_blame!(load_error) end add_template_helper(class_name.constantize) @@ -90,10 +91,9 @@ module ActionController #:nodoc: private def inherited(child) inherited_without_helper(child) - begin - child.helper(child.controller_path) - rescue ArgumentError, LoadError - # No default helper available for this controller + begin child.helper(child.controller_path) + rescue MissingSourceFile => e + raise unless e.path == "helpers/#{child.controller_path}_helper.rb" end end end diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 6d5f108484..28d692aa5b 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -312,7 +312,7 @@ module ActionController route_file = defined?(RAILS_ROOT) ? File.join(RAILS_ROOT, 'config', 'routes') : nil require_dependency(route_file) if route_file rescue LoadError, ScriptError => e - raise RoutingError, "Cannot load config/routes.rb:\n #{e.message}" + raise RoutingError.new("Cannot load config/routes.rb:\n #{e.message}").copy_blame!(e) ensure # Ensure that there is at least one route: connect(':controller/:action/:id', :action => 'index', :id => nil) if @routes.empty? end diff --git a/actionpack/lib/action_controller/templates/rescues/_request_and_response.rhtml b/actionpack/lib/action_controller/templates/rescues/_request_and_response.rhtml index 30a1a05d1f..23e622a47a 100644 --- a/actionpack/lib/action_controller/templates/rescues/_request_and_response.rhtml +++ b/actionpack/lib/action_controller/templates/rescues/_request_and_response.rhtml @@ -1,6 +1,8 @@ -<% if @exception.blamed_files && !@exception.blamed_files.empty? %> - Show blamed files - +<% unless @exception.blamed_files.blank? %> + <% if (hide = @exception.blamed_files.length > 8) %> + Show blamed files + <% end %> +
><%=h @exception.describe_blame %>
<% end %> <% if defined?(Breakpoint) %> -- cgit v1.2.3