Skip to content

Commit

Permalink
Set error code to 1 if generator could not be found (rails#53028)
Browse files Browse the repository at this point in the history
  • Loading branch information
coezbek authored Sep 25, 2024
1 parent 3997ed6 commit 1a36a4a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* Exit `rails g` with code 1 if generator could not be found.

Previously `rails g` returned 0, which would make it harder to catch typos in scripts calling `rails g`.

*Christopher Özbek*

* Remove `require_*` statements from application.css to align with the transition from Sprockets to Propshaft.

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.
Expand Down
1 change: 1 addition & 0 deletions railties/lib/rails/generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def invoke(namespace, args = ARGV, config = {})
#{error.detailed_message}
Run `bin/rails generate --help` for more options.
MSG
exit 1
end
end

Expand Down
18 changes: 15 additions & 3 deletions railties/test/generators_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,23 @@ def test_simple_invoke

def test_invoke_when_generator_is_not_found
name = :unknown
output = capture(:stdout) { Rails::Generators.invoke name }
output = capture(:stdout) {
assert_raises SystemExit do
Rails::Generators.invoke name
end
}
assert_match "Could not find generator '#{name}'.", output
assert_match "`bin/rails generate --help`", output
assert_no_match "Did you mean", output
end

def test_generator_suggestions
name = :migrationz
output = capture(:stdout) { Rails::Generators.invoke name }
output = capture(:stdout) {
assert_raises SystemExit do
Rails::Generators.invoke name
end
}
assert_match "Did you mean? migration", output
end

Expand All @@ -43,7 +51,11 @@ def test_generator_suggestions_except_en_locale
I18n.available_locales = :ja
I18n.default_locale = :ja
name = :tas
output = capture(:stdout) { Rails::Generators.invoke name }
output = capture(:stdout) {
assert_raises SystemExit do
Rails::Generators.invoke name
end
}
assert_match "Did you mean? task", output
ensure
I18n.available_locales = orig_available_locales
Expand Down

0 comments on commit 1a36a4a

Please sign in to comment.