Skip to content

Commit 723e69c

Browse files
committed
Document developer-facing change to config.action_dispatch.show_exceptions default
Support for the new `action_dispatch.show_exceptions` values was introduced in [e28f147][]. Alongside the change to introduce new values (like `:all`, `:rescuable`, `:none`), the default behavior was changed for `Rails.env.test?`. Prior to that commit, the `test` environment's default value was `false` (introduced in [d898a4b][]) (which corresponds to the new `:none` setting). The new default behavior has some unintended negative side effects that impact the feedback loop at the core of test-driven development. When errors are rescued and transformed into HTML pages, the context of the cause of failure is obscured by additional layers of information. First, this commit adds more prominent entries to the Upgrading and Configuring guides, as well as the 7.1 Release Notes to document the details of the configuration and its new values. Next, this commit adds more documentation around the change in default behavior. To start, it mentions the new value in the sections for the affected test types: Controller, Integration, and System. [e28f147]: rails@e28f147 [d898a4b]: rails@d898a4b
1 parent dcd13fc commit 723e69c

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

guides/source/configuring.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,25 @@ The default value depends on the `config.load_defaults` target version:
20202020
Enables logging those unhandled exceptions configured in `rescue_responses`. It
20212021
defaults to `true`.
20222022

2023+
#### `config.action_dispatch.show_exceptions`
2024+
2025+
The `config.action_dispatch.show_exceptions` configuration controls how Action Pack (specifically the [`ActionDispatch::ShowExceptions`](/configuring.html#actiondispatch-showexceptions) middleware) handles exceptions raised while responding to requests.
2026+
2027+
Setting the value to `:all` or `true` configures Action Pack to rescue from exceptions and render corresponding error pages. For example, Action Pack would rescue from an `ActiveRecord::RecordNotFound` exception and render the contents of `public/404.html` with a `404 Not found` status code.
2028+
2029+
Setting the value to `:rescueable` configures Action Pack rescue from exceptions defined in [`config.action_dispatch.rescue_responses`](/configuring.html#config-action-dispatch-rescue-responses), and raise all others. For example, Action Pack would rescue from `ActiveRecord::RecordNotFound`, but would raise a `NoMethodError`.
2030+
2031+
Setting the value to `:none` or `false` configures Action Pack raise all exceptions.
2032+
2033+
* `:all`, `true` - render error pages for all exceptions
2034+
* `:rescuable` - render error pages for exceptions declared by [`config.action_dispatch.rescue_responses`](/configuring.html#config-action-dispatch-rescue-responses)
2035+
* `:none`, `false` - raise all exceptions
2036+
2037+
| Starting with version | The default value is |
2038+
| --------------------- | --------------------- |
2039+
| (original) | `true` |
2040+
| 7.1 | `:all` |
2041+
20232042
#### `ActionDispatch::Callbacks.before`
20242043

20252044
Takes a block of code to run before the request.

guides/source/testing.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,8 @@ By default, system tests are run with the Selenium driver, using the Chrome
857857
browser, and a screen size of 1400x1400. The next section explains how to
858858
change the default settings.
859859

860+
By default, Rails will attempt to rescue from exceptions raised during tests and respond with HTML error pages. This behavior can be controlled by the [`config.action_dispatch.show_exceptions`](/configuring.html#config-action-dispatch-show-exceptions) configuration.
861+
860862
### Changing the Default Settings
861863

862864
Rails makes changing the default settings for system tests very simple. All
@@ -1112,6 +1114,8 @@ end
11121114

11131115
Here the test is inheriting from `ActionDispatch::IntegrationTest`. This makes some additional helpers available for us to use in our integration tests.
11141116

1117+
By default, Rails will attempt to rescue from exceptions raised during tests and respond with HTML error pages. This behavior can be controlled by the [`config.action_dispatch.show_exceptions`](/configuring.html#config-action-dispatch-show-exceptions) configuration.
1118+
11151119
### Helpers Available for Integration Tests
11161120

11171121
In addition to the standard testing helpers, inheriting from `ActionDispatch::IntegrationTest` comes with some additional helpers available when writing integration tests. Let's get briefly introduced to the three categories of helpers we get to choose from.
@@ -1311,6 +1315,8 @@ NOTE: If you followed the steps in the [Basic Authentication](getting_started.ht
13111315
post articles_url, params: { article: { body: "Rails is awesome!", title: "Hello Rails" } }, headers: { Authorization: ActionController::HttpAuthentication::Basic.encode_credentials("dhh", "secret") }
13121316
```
13131317

1318+
By default, Rails will attempt to rescue from exceptions raised during tests and respond with HTML error pages. This behavior can be controlled by the [`config.action_dispatch.show_exceptions`](/configuring.html#config-action-dispatch-show-exceptions) configuration.
1319+
13141320
### Available Request Types for Functional Tests
13151321

13161322
If you're familiar with the HTTP protocol, you'll know that `get` is a type of request. There are 6 request types supported in Rails functional tests:

guides/source/upgrading_ruby_on_rails.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,20 @@ config.active_record.encryption.support_sha1_for_non_deterministic_encryption =
378378

379379
If you are working with encrypted data, please carefully review the above.
380380

381+
### New ways to handle exceptions in Controller Tests, Integration Tests, and System Tests
382+
383+
The `config.action_dispatch.show_exceptions` configuration controls how Action Pack handles exceptions raised while responding to requests.
384+
385+
Prior to Rails 7.1, setting `config.action_dispatch.show_exceptions = true` configured Action Pack to rescue exceptions and render appropriate HTML error pages, like rendering `public/404.html` with a `404 Not found` status code instead of raising an `ActiveRecord::RecordNotFound` exception. Setting `config.action_dispatch.show_exceptions = false` configured Action Pack to not rescue the exception. Prior to Rails 7.1, new applications were generated with a line in `config/environments/test.rb` that set `config.action_dispatch.show_exceptions = false`.
386+
387+
Rails 7.1 changes the acceptable values from `true` and `false` to `:all`, `:rescuable`, and `:none`.
388+
389+
* `:all` - render HTML error pages for all exceptions (equivalent to `true`)
390+
* `:rescuable` - render HTML error pages for exceptions declared by [`config.action_dispatch.rescue_responses`](/configuring.html#config-action-dispatch-rescue-responses)
391+
* `:none` (equivalent to `false`) - do not rescue from any exceptions
392+
393+
Applications generated by Rails 7.1 or later set `config.action_dispatch.show_exceptions = :rescuable` in their `config/environments/test.rb`. When upgrading, existing applications can change `config.action_dispatch.show_exceptions = :rescuable` to utilize the new behavior, or replace the old values with the corresponding new ones (`true` replaces `:all`, `false` replaces `:none`).
394+
381395
Upgrading from Rails 6.1 to Rails 7.0
382396
-------------------------------------
383397

0 commit comments

Comments
 (0)