From 98349f37a31979b04f01d8be59d0db83620abf24 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 20 Feb 2005 10:51:10 +0000 Subject: Gives Rescues some Love #680 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@709 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/dependencies.rb | 3 ++ .../templates/rescues/_request_and_response.rhtml | 10 ++++++- .../templates/rescues/diagnostics.rhtml | 2 +- activesupport/lib/active_support/dependencies.rb | 35 ++++++++++++++++++++-- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_controller/dependencies.rb b/actionpack/lib/action_controller/dependencies.rb index abf6ca7417..be32417894 100644 --- a/actionpack/lib/action_controller/dependencies.rb +++ b/actionpack/lib/action_controller/dependencies.rb @@ -70,6 +70,9 @@ module ActionController #:nodoc: require_dependency(dependency.to_s) rescue LoadError raise LoadError, "Missing #{layer} #{dependency}.rb" + rescue Object => exception + exception.blame_file! "=> #{layer} #{dependency}.rb" + raise end end 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 aaeebba6f4..d807c4fb79 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,11 @@ +<% unless @exception.blamed_files.empty? %> + Show blamed files + +<% end %> + <% if defined?(Breakpoint) %>

- <%= form_tag({:params => {}, :only_path => true}, "method" => @request.method) %> + <% begin %><%= form_tag({:params => {}, :only_path => true}, "method" => @request.method) %> <% for key, values in @params %> @@ -12,6 +17,9 @@ + <% rescue Exception => e %> + <%=h "Couldn't render breakpoint link due to #{e.class} #{e.message}" %> + <% end %> <% end %> <% diff --git a/actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml b/actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml index c9ea00ef8f..9fb2de5b10 100644 --- a/actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml +++ b/actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml @@ -6,7 +6,7 @@

<%=h @exception.class.to_s %> in - <%=h @request.parameters["controller"].capitalize %>#<%=h @request.parameters["action"] %> + <%=h (@request.parameters["controller"] || "").capitalize %>#<%=h @request.parameters["action"] || "" %>

<%=h Object.const_defined?(:RAILS_ROOT) ? @exception.message.gsub(RAILS_ROOT, "") : @exception.message %>

diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 0a9b8e1d3d..1aae239d71 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -100,7 +100,12 @@ module Dependencies end def load_file(file_path) - Controllers.module_eval(IO.read(file_path), file_path, 1) # Hard coded Controller line here!!! + begin + Controllers.module_eval(IO.read(file_path), file_path, 1) # Hard coded Controller line here!!! + rescue Object => exception + exception.blame_file! file_path + raise + end end end end @@ -125,4 +130,30 @@ class Object #:nodoc: end end end -end \ No newline at end of file + def load(file, *extras) + begin super(file, *extras) + rescue Object => exception + exception.blame_file! file + raise + end + end + def require(file, *extras) + begin super(file, *extras) + rescue Object => exception + exception.blame_file! file + raise + end + end +end + +# Add file-blaming to exceptions +class Exception + def blame_file!(file) + (@blamed_files ||= []).unshift file + end + attr_reader :blamed_files + def describe_blame + return nil if blamed_files.empty? + "This error occured while loading the following files:\n #{blamed_files.join '\n '}" + end +end -- cgit v1.2.3