Skip to content

Commit 3da8993

Browse files
authored
Merge pull request rails#53964 from byroot/missing-controller-500
Return a 500 on MissingController errors
2 parents 78d5233 + a1bfeee commit 3da8993

File tree

4 files changed

+17
-47
lines changed

4 files changed

+17
-47
lines changed

actionpack/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,19 @@
166166
167167
*Jeremy Green*
168168
169+
* A route pointing to a non-existing controller now returns a 500 instead of a 404.
170+
171+
A controller not existing isn't a routing error that should result
172+
in a 404, but a programming error that should result in a 500 and
173+
be reported.
174+
175+
Until recently, this was hard to untangle because of the support
176+
for dynamic `:controller` segment in routes, but since this is
177+
deprecated and will be removed in Rails 8.1, we can now easily
178+
not consider missing controllers as routing errors.
179+
180+
*Jean Boussier*
181+
169182
* Add `check_collisions` option to `ActionDispatch::Session::CacheStore`.
170183

171184
Newly generated session ids use 128 bits of randomness, which is more than

actionpack/lib/action_dispatch/routing/route_set.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ def serve(req)
5959
private
6060
def controller(req)
6161
req.controller_class
62-
rescue NameError => e
63-
raise ActionController::RoutingError, e.message, e.backtrace
6462
end
6563

6664
def dispatch(controller, action, req, res)

actionpack/test/controller/routing_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,12 @@ def test_route_constraints_with_options_method_condition_is_valid
12831283

12841284
def test_route_error_with_missing_controller
12851285
set.draw do
1286-
get "/people" => "missing#index"
1286+
get "/people" => "does_not_exists#index"
12871287
end
12881288

1289-
assert_raises(ActionController::RoutingError) { request_path_params "/people" }
1289+
assert_raises(ActionDispatch::MissingController, match: "uninitialized constant DoesNotExistsController") do
1290+
request_path_params "/people"
1291+
end
12901292
end
12911293

12921294
def test_recognize_with_encoded_id_and_regex

actionpack/test/dispatch/routing_test.rb

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4998,49 +4998,6 @@ def test_positional_args_with_format_false
49984998
end
49994999
end
50005000

5001-
class TestErrorsInController < ActionDispatch::IntegrationTest
5002-
class ::PostsController < ActionController::Base
5003-
def foo
5004-
nil.i_do_not_exist
5005-
end
5006-
5007-
def bar
5008-
NonExistingClass.new
5009-
end
5010-
end
5011-
5012-
Routes = ActionDispatch::Routing::RouteSet.new
5013-
Routes.draw do
5014-
ActionDispatch.deprecator.silence do
5015-
get "/:controller(/:action)"
5016-
end
5017-
end
5018-
5019-
APP = build_app Routes
5020-
5021-
def app
5022-
APP
5023-
end
5024-
5025-
def test_legit_no_method_errors_are_not_caught
5026-
get "/posts/foo"
5027-
assert_equal 500, response.status
5028-
end
5029-
5030-
def test_legit_name_errors_are_not_caught
5031-
get "/posts/bar"
5032-
assert_equal 500, response.status
5033-
end
5034-
5035-
def test_legit_routing_not_found_responses
5036-
get "/posts/baz"
5037-
assert_equal 404, response.status
5038-
5039-
get "/i_do_not_exist"
5040-
assert_equal 404, response.status
5041-
end
5042-
end
5043-
50445001
class TestPartialDynamicPathSegments < ActionDispatch::IntegrationTest
50455002
Routes = ActionDispatch::Routing::RouteSet.new
50465003
Routes.draw do

0 commit comments

Comments
 (0)