From 2a3a6e5efcd1971673cf4cccd1903b44fd6660a5 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Sat, 14 May 2022 09:42:13 -0400 Subject: [PATCH] Improve `rails s` error message when no server could be found. Fix: https://github.com/rails/rails/issues/45092 Up until 3.0, `rails s` would always at least find webrick. But since it was removed in Ruby 3.0, it's now possible to end up with no available server at all. In such case we should recommend adding puma to the Gemfile. --- railties/lib/rails/commands/server/server_command.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index ddbcf1f7e4a..831b642c17e 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -96,6 +96,7 @@ module Rails # Hard-coding a bunch of handlers here as we don't have a public way of # querying them from the Rack::Handler registry. RACK_SERVERS = %w(cgi fastcgi webrick lsws scgi thin puma unicorn falcon) + RECOMMENDED_SERVER = "puma" DEFAULT_PORT = 3000 DEFAULT_PIDFILE = "tmp/pids/server.pid" @@ -253,7 +254,15 @@ module Rails end def rack_server_suggestion(server) - if server.in?(RACK_SERVERS) + if server.nil? + <<~MSG + Could not find a server gem. Maybe you need to add one to the Gemfile? + + gem "#{RECOMMENDED_SERVER}" + + Run `bin/rails server --help` for more options. + MSG + elsif server.in?(RACK_SERVERS) <<~MSG Could not load server "#{server}". Maybe you need to the add it to the Gemfile?