Gives Rescues some Love #680

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@709 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 6a7fc51c
......@@ -70,6 +70,9 @@ def require_dependencies(layer, dependencies)
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
......
<% unless @exception.blamed_files.empty? %>
<a href="#" onclick="document.getElementById('blame_trace').style.display='block'; return false;">Show blamed files</a>
<pre id="blame_trace" style="display:none"><code><%=h @exception.describe_blame %></code></pre>
<% end %>
<% if defined?(Breakpoint) %>
<br /><br />
<%= form_tag({:params => {}, :only_path => true}, "method" => @request.method) %>
<% begin %><%= form_tag({:params => {}, :only_path => true}, "method" => @request.method) %>
<input type="hidden" name="BP-RETRY" value="1" />
<% for key, values in @params %>
......@@ -12,6 +17,9 @@
<input type="submit" value="Retry with Breakpoint" />
</form>
<% rescue Exception => e %>
<%=h "Couldn't render breakpoint link due to #{e.class} #{e.message}" %>
<% end %>
<% end %>
<%
......
......@@ -6,7 +6,7 @@
<h1>
<%=h @exception.class.to_s %> in
<%=h @request.parameters["controller"].capitalize %>#<%=h @request.parameters["action"] %>
<%=h (@request.parameters["controller"] || "<controller not set>").capitalize %>#<%=h @request.parameters["action"] || "<action not set>" %>
</h1>
<p><%=h Object.const_defined?(:RAILS_ROOT) ? @exception.message.gsub(RAILS_ROOT, "") : @exception.message %></p>
......
......@@ -100,7 +100,12 @@ def clear
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 @@ def const_missing(class_id)
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册