1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #41874 from jacobherrington/error-page-css-and-a11y-improvements

Error page CSS and a11y improvements
This commit is contained in:
Andrew White 2021-04-10 12:34:30 +01:00 committed by GitHub
commit 64107f367a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 61 additions and 45 deletions

View file

@ -1,3 +1,7 @@
* Remove inline styles and address basic accessibilty issues on rescue templates.
*Jacob Herrington*
* Add support for 'private, no-store' Cache-Control headers. * Add support for 'private, no-store' Cache-Control headers.
Previously, 'no-store' was exclusive; no other directives could be specified. Previously, 'no-store' was exclusive; no other directives could be specified.

View file

@ -11,7 +11,7 @@
<b>Did you mean?</b> <b>Did you mean?</b>
<ul> <ul>
<% corrections.each do |correction| %> <% corrections.each do |correction| %>
<li style="list-style-type: none"><%= h correction %></li> <li class="correction"><%= h correction %></li>
<% end %> <% end %>
</ul> </ul>
<% end %> <% end %>

View file

@ -1,17 +1,17 @@
<h2 style="margin-top: 30px">Request</h2> <h2 class="request-heading">Request</h2>
<% if params_valid? %> <% if params_valid? %>
<p><b>Parameters</b>:</p> <pre><%= debug_params(@request.filtered_parameters) %></pre> <p><b>Parameters</b>:</p> <pre><%= debug_params(@request.filtered_parameters) %></pre>
<% end %> <% end %>
<div class="details"> <div class="details">
<div class="summary"><a href="#" onclick="return toggleSessionDump()">Toggle session dump</a></div> <div class="summary"><a href="#" onclick="return toggleSessionDump()">Toggle session dump</a></div>
<div id="session_dump" style="display:none"><pre><%= debug_hash @request.session %></pre></div> <div id="session_dump" class="hidden"><pre><%= debug_hash @request.session %></pre></div>
</div> </div>
<div class="details"> <div class="details">
<div class="summary"><a href="#" onclick="return toggleEnvDump()">Toggle env dump</a></div> <div class="summary"><a href="#" onclick="return toggleEnvDump()">Toggle env dump</a></div>
<div id="env_dump" style="display:none"><pre><%= debug_hash @request.env.slice(*@request.class::ENV_METHODS) %></pre></div> <div id="env_dump" class="hidden"><pre><%= debug_hash @request.env.slice(*@request.class::ENV_METHODS) %></pre></div>
</div> </div>
<h2 style="margin-top: 30px">Response</h2> <h2 class="response-heading">Response</h2>
<p><b>Headers</b>:</p> <pre><%= debug_headers(defined?(@response) ? @response.headers : {}) %></pre> <p><b>Headers</b>:</p> <pre><%= debug_headers(defined?(@response) ? @response.headers : {}) %></pre>

View file

@ -14,7 +14,7 @@
<% traces.each do |name, trace| %> <% traces.each do |name, trace| %>
<div id="<%= "#{name.gsub(/\s/, '-')}-#{error_index}" %>" style="display: <%= (name == trace_to_show) ? 'block' : 'none' %>;"> <div id="<%= "#{name.gsub(/\s/, '-')}-#{error_index}" %>" style="display: <%= (name == trace_to_show) ? 'block' : 'none' %>;">
<code style="font-size: 11px;"> <code class="traces">
<% trace.each do |frame| %> <% trace.each do |frame| %>
<a class="trace-frames trace-frames-<%= error_index %>" data-exception-object-id="<%= frame[:exception_object_id] %>" data-frame-id="<%= frame[:id] %>" href="#"> <a class="trace-frames trace-frames-<%= error_index %>" data-exception-object-id="<%= frame[:exception_object_id] %>" data-frame-id="<%= frame[:id] %>" href="#">
<%= frame[:trace] %> <%= frame[:trace] %>

View file

@ -1,7 +1,7 @@
<header> <header>
<h1>Blocked host: <%= @host %></h1> <h1>Blocked host: <%= @host %></h1>
</header> </header>
<div id="container"> <main role="main" id="container">
<h2>To allow requests to <%= @host %>, add the following to your environment configuration:</h2> <h2>To allow requests to <%= @host %>, add the following to your environment configuration:</h2>
<pre>config.hosts &lt;&lt; "<%= @host %>"</pre> <pre>config.hosts &lt;&lt; "<%= @host %>"</pre>
</div> </main>

View file

@ -7,7 +7,7 @@
</h1> </h1>
</header> </header>
<div id="container"> <main role="main" id="container">
<%= render "rescues/message_and_suggestions", exception: @exception %> <%= render "rescues/message_and_suggestions", exception: @exception %>
<%= render "rescues/actions", exception: @exception, request: @request %> <%= render "rescues/actions", exception: @exception, request: @request %>
@ -20,16 +20,16 @@
<% @exception_wrapper.wrapped_causes.each.with_index(1) do |wrapper, index| %> <% @exception_wrapper.wrapped_causes.each.with_index(1) do |wrapper, index| %>
<div class="details"> <div class="details">
<a class="summary" href="#" style="color: #F0F0F0; text-decoration: none; background: #C52F24; border-bottom: none;" onclick="return toggle(<%= wrapper.exception.object_id %>)"> <a class="summary" href="#" onclick="return toggle(<%= wrapper.exception.object_id %>)">
<%= wrapper.exception.class.name %>: <%= h wrapper.exception.message %> <%= wrapper.exception.class.name %>: <%= h wrapper.exception.message %>
</a> </a>
</div> </div>
<div id="<%= wrapper.exception.object_id %>" style="display: none;"> <div id="<%= wrapper.exception.object_id %>" class="hidden">
<%= render "rescues/source", source_extracts: wrapper.source_extracts, show_source_idx: wrapper.source_to_show_id, error_index: index %> <%= render "rescues/source", source_extracts: wrapper.source_extracts, show_source_idx: wrapper.source_to_show_id, error_index: index %>
<%= render "rescues/trace", traces: wrapper.traces, trace_to_show: wrapper.trace_to_show, error_index: index %> <%= render "rescues/trace", traces: wrapper.traces, trace_to_show: wrapper.trace_to_show, error_index: index %>
</div> </div>
<% end %> <% end %>
<%= render template: "rescues/_request_and_response" %> <%= render template: "rescues/_request_and_response" %>
</div> </main>

View file

@ -1,4 +1,4 @@
<header> <header role="banner">
<h1> <h1>
<%= @exception.class.to_s %> <%= @exception.class.to_s %>
<% if @request.parameters['controller'] %> <% if @request.parameters['controller'] %>
@ -7,7 +7,7 @@
</h1> </h1>
</header> </header>
<div id="container"> <main role="main" id="container">
<h2> <h2>
<%= h @exception.message %> <%= h @exception.message %>
<% if defined?(ActiveStorage) && @exception.message.match?(%r{#{ActiveStorage::Blob.table_name}|#{ActiveStorage::Attachment.table_name}}) %> <% if defined?(ActiveStorage) && @exception.message.match?(%r{#{ActiveStorage::Blob.table_name}|#{ActiveStorage::Attachment.table_name}}) %>
@ -21,4 +21,4 @@
<%= render "rescues/source", source_extracts: @source_extracts, show_source_idx: @show_source_idx %> <%= render "rescues/source", source_extracts: @source_extracts, show_source_idx: @show_source_idx %>
<%= render "rescues/trace", traces: @traces, trace_to_show: @trace_to_show %> <%= render "rescues/trace", traces: @traces, trace_to_show: @trace_to_show %>
<%= render template: "rescues/_request_and_response" %> <%= render template: "rescues/_request_and_response" %>
</div> </main>

View file

@ -49,11 +49,19 @@
line-height: 25px; line-height: 25px;
} }
code.traces {
font-size: 11px;
}
.response-heading, .request-heading {
margin-top: 30px;
}
.exception-message { .exception-message {
padding: 8px 0; padding: 8px 0;
} }
.exception-message .message{ .exception-message .message {
margin-bottom: 8px; margin-bottom: 8px;
line-height: 25px; line-height: 25px;
font-size: 1.5em; font-size: 1.5em;
@ -75,6 +83,13 @@
display: block; display: block;
} }
a.summary {
color: #F0F0F0;
text-decoration: none;
background: #C52F24;
border-bottom: none;
}
.details pre { .details pre {
margin: 5px; margin: 5px;
border: none; border: none;
@ -114,7 +129,7 @@
.source .data .line_numbers { .source .data .line_numbers {
background-color: #ECECEC; background-color: #ECECEC;
color: #AAA; color: #555;
padding: 1em .5em; padding: 1em .5em;
border-right: 1px solid #DDD; border-right: 1px solid #DDD;
text-align: right; text-align: right;
@ -143,6 +158,10 @@
display: none; display: none;
} }
.correction {
list-style-type: none;
}
input[type="submit"] { input[type="submit"] {
color: white; color: white;
background-color: #C00; background-color: #C00;
@ -165,15 +184,14 @@
transform: translateY(1px) transform: translateY(1px)
} }
a { color: #980905; } a { color: #980905; }
a:visited { color: #666; } a:visited { color: #666; }
a.trace-frames { a.trace-frames {
color: #666; color: #666;
overflow-wrap: break-word; overflow-wrap: break-word;
} }
a:hover { color: #C00; } a:hover, a.trace-frames.selected { color: #C00; }
a.trace-frames.selected { color: #C00 } a.summary:hover { color: #FFF; }
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
body { body {
@ -181,11 +199,7 @@
color: #ECECEC; color: #ECECEC;
} }
.details { .details, .summary {
border-color: #666;
}
.summary {
border-color: #666; border-color: #666;
} }
@ -220,8 +234,7 @@
a { color: #C00; } a { color: #C00; }
a.trace-frames { color: #999; } a.trace-frames { color: #999; }
a:hover { color: #E9382B; } a:hover, a.trace-frames.selected { color: #E9382B; }
a.trace-frames.selected { color: #E9382B; }
} }
<%= yield :style %> <%= yield :style %>
@ -229,8 +242,7 @@
<script> <script>
var toggle = function(id) { var toggle = function(id) {
var s = document.getElementById(id).style; document.getElementById(id).classList.toggle('hidden');
s.display = s.display == 'none' ? 'block' : 'none';
return false; return false;
} }
var show = function(id) { var show = function(id) {
@ -249,7 +261,7 @@
</head> </head>
<body> <body>
<%= yield %> <%= yield %>
</body> </body>
</html> </html>

View file

@ -1,8 +1,8 @@
<header> <header role="banner">
<h1>No template for interactive request</h1> <h1>No template for interactive request</h1>
</header> </header>
<div id="container"> <main id="container">
<h2><%= h @exception.message %></h2> <h2><%= h @exception.message %></h2>
<p class="summary"> <p class="summary">
@ -16,4 +16,4 @@
since we expect an HTML template since we expect an HTML template
to be rendered for such requests. If that's the case, carry on. to be rendered for such requests. If that's the case, carry on.
</p> </p>
</div> </main>

View file

@ -1,11 +1,11 @@
<header> <header role="banner">
<h1>Template is missing</h1> <h1>Template is missing</h1>
</header> </header>
<div id="container"> <main role="main" id="container">
<h2><%= h @exception.message %></h2> <h2><%= h @exception.message %></h2>
<%= render "rescues/source", source_extracts: @source_extracts, show_source_idx: @show_source_idx %> <%= render "rescues/source", source_extracts: @source_extracts, show_source_idx: @show_source_idx %>
<%= render "rescues/trace", traces: @traces, trace_to_show: @trace_to_show %> <%= render "rescues/trace", traces: @traces, trace_to_show: @trace_to_show %>
<%= render template: "rescues/_request_and_response" %> <%= render template: "rescues/_request_and_response" %>
</div> </main>

View file

@ -1,7 +1,7 @@
<header> <header role="banner">
<h1>Routing Error</h1> <h1>Routing Error</h1>
</header> </header>
<div id="container"> <main role="main" id="container">
<h2><%= h @exception.message %></h2> <h2><%= h @exception.message %></h2>
<% unless @exception.failures.empty? %> <% unless @exception.failures.empty? %>
<p> <p>
@ -29,4 +29,4 @@
<% end %> <% end %>
<%= render template: "rescues/_request_and_response" %> <%= render template: "rescues/_request_and_response" %>
</div> </main>

View file

@ -1,11 +1,11 @@
<header> <header role="banner">
<h1> <h1>
<%= @exception.cause.class.to_s %> in <%= @exception.cause.class.to_s %> in
<%= @request.parameters["controller"].camelize if @request.parameters["controller"] %>#<%= @request.parameters["action"] %> <%= @request.parameters["controller"].camelize if @request.parameters["controller"] %>#<%= @request.parameters["action"] %>
</h1> </h1>
</header> </header>
<div id="container"> <main role="main" id="container">
<p> <p>
Showing <i><%= @exception.file_name %></i> where line <b>#<%= @exception.line_number %></b> raised: Showing <i><%= @exception.file_name %></i> where line <b>#<%= @exception.line_number %></b> raised:
</p> </p>
@ -17,4 +17,4 @@
<%= render "rescues/trace", traces: @traces, trace_to_show: @trace_to_show %> <%= render "rescues/trace", traces: @traces, trace_to_show: @trace_to_show %>
<%= render template: "rescues/_request_and_response" %> <%= render template: "rescues/_request_and_response" %>
</div> </main>

View file

@ -1,6 +1,6 @@
<header> <header role="banner">
<h1>Unknown action</h1> <h1>Unknown action</h1>
</header> </header>
<div id="container"> <main role="main" id="container">
<%= render "rescues/message_and_suggestions", exception: @exception %> <%= render "rescues/message_and_suggestions", exception: @exception %>
</div> </main>