From 9734c9b6fe2d2e4a980d8ad94c5de0300b23c809 Mon Sep 17 00:00:00 2001
From: ThibG <thib@sitedethib.com>
Date: Sun, 20 Dec 2020 18:05:03 +0100
Subject: [PATCH] Add clean error message when RAILS_ENV is unset (#15381)

By default, an unset RAILS_ENV is understood as RAILS_ENV=development.

However, this is not what most people expect, and due to development-only
dependencies, users are often left with confusing error messages.

This commit changes it so that an explicit RAILS_ENV is required, and
failing that, an error message is displayed before loading the app.

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
---
 config/boot.rb | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/config/boot.rb b/config/boot.rb
index f3e36203aa..6cde5319d4 100644
--- a/config/boot.rb
+++ b/config/boot.rb
@@ -1,3 +1,8 @@
+unless ENV.key?('RAILS_ENV')
+  STDERR.puts 'ERROR: Missing RAILS_ENV environment variable, please set it to "production", "development", or "test".'
+  exit 1
+end
+
 ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
 
 require 'bundler/setup' # Set up gems listed in the Gemfile.
-- 
GitLab