From 11af089cee0a0e744e267d32becfe2c66a586d31 Mon Sep 17 00:00:00 2001
From: Joshua Peek
Date: Sat, 2 May 2009 23:02:22 -0500
Subject: Extract ActionController rescue templates into Rescue and
ShowExceptions middleware.
This commit breaks all exception catching plugins like ExceptionNotifier. These plugins should be rewritten as middleware instead overriding Controller#rescue_action_in_public.
---
.../templates/rescues/_request_and_response.erb | 24 ++++++++++++++++++
.../middleware/templates/rescues/_trace.erb | 26 +++++++++++++++++++
.../middleware/templates/rescues/diagnostics.erb | 10 ++++++++
.../middleware/templates/rescues/layout.erb | 29 ++++++++++++++++++++++
.../templates/rescues/missing_template.erb | 2 ++
.../middleware/templates/rescues/routing_error.erb | 10 ++++++++
.../templates/rescues/template_error.erb | 21 ++++++++++++++++
.../templates/rescues/unknown_action.erb | 2 ++
8 files changed, 124 insertions(+)
create mode 100644 actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
create mode 100644 actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb
create mode 100644 actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
create mode 100644 actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb
create mode 100644 actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.erb
create mode 100644 actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
create mode 100644 actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb
create mode 100644 actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb
(limited to 'actionpack/lib/action_dispatch/middleware/templates')
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
new file mode 100644
index 0000000000..5224403dab
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
@@ -0,0 +1,24 @@
+<% unless @exception.blamed_files.blank? %>
+ <% if (hide = @exception.blamed_files.length > 8) %>
+ Show blamed files
+ <% end %>
+ ><%=h @exception.describe_blame %>
+<% end %>
+
+<%
+ clean_params = @request.parameters.clone
+ clean_params.delete("action")
+ clean_params.delete("controller")
+
+ request_dump = clean_params.empty? ? 'None' : clean_params.inspect.gsub(',', ",\n")
+%>
+
+Request
+Parameters:
<%=h request_dump %>
+
+Show session dump
+<%= debug(@request.session.instance_variable_get("@data")) %>
+
+
+Response
+Headers:
<%=h @response ? @response.headers.inspect.gsub(',', ",\n") : 'None' %>
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb
new file mode 100644
index 0000000000..bb2d8375bd
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb
@@ -0,0 +1,26 @@
+<%
+ traces = [
+ ["Application Trace", @exception.application_backtrace],
+ ["Framework Trace", @exception.framework_backtrace],
+ ["Full Trace", @exception.clean_backtrace]
+ ]
+ names = traces.collect {|name, trace| name}
+%>
+
+RAILS_ROOT: <%= defined?(RAILS_ROOT) ? RAILS_ROOT : "unset" %>
+
+
+ <% names.each do |name| %>
+ <%
+ show = "document.getElementById('#{name.gsub /\s/, '-'}').style.display='block';"
+ hide = (names - [name]).collect {|hide_name| "document.getElementById('#{hide_name.gsub /\s/, '-'}').style.display='none';"}
+ %>
+
<%= name %> <%= '|' unless names.last == name %>
+ <% end %>
+
+ <% traces.each do |name, trace| %>
+
;">
+
<%= trace.join "\n" %>
+
+ <% end %>
+
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
new file mode 100644
index 0000000000..693e56270a
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
@@ -0,0 +1,10 @@
+
+ <%=h @exception.class.to_s %>
+ <% if @request.parameters['controller'] %>
+ in <%=h @request.parameters['controller'].humanize %>Controller<% if @request.parameters['action'] %>#<%=h @request.parameters['action'] %><% end %>
+ <% end %>
+
+<%=h @exception.clean_message %>
+
+<%= render :file => "rescues/_trace.erb" %>
+<%= render :file => "rescues/_request_and_response.erb" %>
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb
new file mode 100644
index 0000000000..6c32fb17b8
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb
@@ -0,0 +1,29 @@
+
+
+ Action Controller: Exception caught
+
+
+
+
+<%= yield %>
+
+
+
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.erb
new file mode 100644
index 0000000000..dbfdf76947
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.erb
@@ -0,0 +1,2 @@
+Template is missing
+<%=h @exception.message %>
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
new file mode 100644
index 0000000000..ccfa858cce
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
@@ -0,0 +1,10 @@
+Routing Error
+<%=h @exception.message %>
+<% unless @exception.failures.empty? %>
+
Failure reasons:
+
+ <% @exception.failures.each do |route, reason| %>
+ <%=h route.inspect.gsub('\\', '') %>
failed because <%=h reason.downcase %>
+ <% end %>
+
+<% end %>
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb
new file mode 100644
index 0000000000..02fa18211d
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb
@@ -0,0 +1,21 @@
+
+ <%=h @exception.original_exception.class.to_s %> in
+ <%=h @request.parameters["controller"].capitalize if @request.parameters["controller"]%>#<%=h @request.parameters["action"] %>
+
+
+
+ Showing <%=h @exception.file_name %> where line #<%=h @exception.line_number %> raised:
+
<%=h @exception.message %>
+
+
+Extracted source (around line #<%=h @exception.line_number %>):
+
<%=h @exception.source_extract %>
+
+<%=h @exception.sub_template_message %>
+
+<% @real_exception = @exception
+ @exception = @exception.original_exception || @exception %>
+<%= render :file => "rescues/_trace.erb" %>
+<% @exception = @real_exception %>
+
+<%= render :file => "rescues/_request_and_response.erb" %>
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb
new file mode 100644
index 0000000000..683379da10
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb
@@ -0,0 +1,2 @@
+Unknown action
+<%=h @exception.message %>
--
cgit v1.2.3