Skip to content

Commit 1a36a4a

Browse files
authored
Set error code to 1 if generator could not be found (rails#53028)
1 parent 3997ed6 commit 1a36a4a

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

railties/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Exit `rails g` with code 1 if generator could not be found.
2+
3+
Previously `rails g` returned 0, which would make it harder to catch typos in scripts calling `rails g`.
4+
5+
*Christopher Özbek*
6+
17
* Remove `require_*` statements from application.css to align with the transition from Sprockets to Propshaft.
28

39
With Propshaft as the default asset pipeline in Rails 8, the require_tree and require_self clauses in application.css are no longer necessary, as they were specific to Sprockets. Additionally, the comment has been updated to clarify that CSS precedence now follows standard cascading order without automatic prioritization by the asset pipeline.

railties/lib/rails/generators.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ def invoke(namespace, args = ARGV, config = {})
272272
#{error.detailed_message}
273273
Run `bin/rails generate --help` for more options.
274274
MSG
275+
exit 1
275276
end
276277
end
277278

railties/test/generators_test.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,23 @@ def test_simple_invoke
2525

2626
def test_invoke_when_generator_is_not_found
2727
name = :unknown
28-
output = capture(:stdout) { Rails::Generators.invoke name }
28+
output = capture(:stdout) {
29+
assert_raises SystemExit do
30+
Rails::Generators.invoke name
31+
end
32+
}
2933
assert_match "Could not find generator '#{name}'.", output
3034
assert_match "`bin/rails generate --help`", output
3135
assert_no_match "Did you mean", output
3236
end
3337

3438
def test_generator_suggestions
3539
name = :migrationz
36-
output = capture(:stdout) { Rails::Generators.invoke name }
40+
output = capture(:stdout) {
41+
assert_raises SystemExit do
42+
Rails::Generators.invoke name
43+
end
44+
}
3745
assert_match "Did you mean? migration", output
3846
end
3947

@@ -43,7 +51,11 @@ def test_generator_suggestions_except_en_locale
4351
I18n.available_locales = :ja
4452
I18n.default_locale = :ja
4553
name = :tas
46-
output = capture(:stdout) { Rails::Generators.invoke name }
54+
output = capture(:stdout) {
55+
assert_raises SystemExit do
56+
Rails::Generators.invoke name
57+
end
58+
}
4759
assert_match "Did you mean? task", output
4860
ensure
4961
I18n.available_locales = orig_available_locales

0 commit comments

Comments
 (0)