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

Merge pull request #40567 from hahmed/ha/formatted-error-messages

Display exception messages using simple_format
This commit is contained in:
Rafael França 2020-11-09 18:11:06 -05:00 committed by GitHub
commit a538e4dee5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 9 deletions

View file

@ -1,5 +1,7 @@
<% if exception.respond_to?(:original_message) && exception.respond_to?(:corrections) %>
<h2><%= h exception.original_message %></h2>
<div class="exception-message">
<%= simple_format h(exception.original_message), { class: "message" }, wrapper_tag: "div" %>
</div>
<%
# The 'did_you_mean' gem can raise exceptions when calling #corrections on
# the exception. If it does there are no corrections to show.
@ -14,5 +16,7 @@
</ul>
<% end %>
<% else %>
<h2><%= h exception.message %></h2>
<div class="exception-message">
<%= simple_format h(exception.message), { class: "message" }, wrapper_tag: "div" %>
</div>
<% end %>

View file

@ -49,6 +49,18 @@
line-height: 25px;
}
.exception-message {
padding: 8px 0;
}
.exception-message .message{
margin-bottom: 8px;
line-height: 25px;
font-size: 1.5em;
font-weight: bold;
color: #C00;
}
.details {
border: 1px solid #D0D0D0;
border-radius: 4px;

View file

@ -629,7 +629,9 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
# Assert correct error
assert_response 500
assert_select "h2", /error in framework/
assert_select "div.exception-message" do
assert_select "div", /error in framework/
end
# assert source view line is the call to method_that_raises
assert_select "div.source:not(.hidden)" do
@ -637,7 +639,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
end
# assert first source view (hidden) that throws the error
assert_select "div.source:first" do
assert_select "div.source" do
assert_select "pre .line.active", /raise StandardError\.new/
end
@ -680,7 +682,9 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
# Assert correct error
assert_response 500
assert_select "h2", /Third error/
assert_select "div.exception-message" do
assert_select "div", /Third error/
end
# assert source view line shows the last error
assert_select "div.source:not(.hidden)" do
@ -749,7 +753,9 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
get "/nil_annoted_source_code_error", headers: { "action_dispatch.show_exceptions" => true, "action_dispatch.logger" => logger }
assert_select "header h1", /DebugExceptionsTest::Boomer::NilAnnotedSourceCodeError/
assert_select "#container h2", /nil annoted_source_code/
assert_select "#container div.exception-message" do
assert_select "div", /nil annoted_source_code/
end
end
test "debug exceptions app shows diagnostics for template errors that contain UTF-8 characters" do

View file

@ -8,6 +8,7 @@ module ApplicationTests
class MailerPreviewsTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
include Rack::Test::Methods
include ERB::Util
def setup
build_app
@ -299,7 +300,7 @@ module ApplicationTests
app("development")
get "/rails/mailers/notifier"
assert_predicate last_response, :not_found?
assert_match "Mailer preview &#39;notifier&#39; not found", last_response.body
assert_match "Mailer preview &#39;notifier&#39; not found", h(last_response.body)
end
test "mailer preview email not found" do
@ -329,7 +330,7 @@ module ApplicationTests
get "/rails/mailers/notifier/bar"
assert_predicate last_response, :not_found?
assert_match "Email &#39;bar&#39; not found in NotifierPreview", last_response.body
assert_match "Email &#39;bar&#39; not found in NotifierPreview", h(last_response.body)
end
test "mailer preview NullMail" do
@ -385,7 +386,7 @@ module ApplicationTests
get "/rails/mailers/notifier/foo?part=text%2Fhtml"
assert_predicate last_response, :not_found?
assert_match "Email part &#39;text/html&#39; not found in NotifierPreview#foo", last_response.body
assert_match "Email part &#39;text/html&#39; not found in NotifierPreview#foo", h(last_response.body)
end
test "message header uses full display names" do