Backtrace when mistyping a rails command

When you mistype a rails command from the command line you get a long backtrace. This isn’t really helpful for a beginner who has to scroll to the top to see a helpful message. The backtrace won’t be any help to a user anyway.

$ bin/rails start

rails aborted!
Don't know how to build task 'start' (See the list of available tasks with `rails --tasks`)
Did you mean?  stats
               restart
/Users/petrik/Projects/All/_forks/rails/railties/lib/rails/commands/rake/rake_command.rb:22:in `block (2 levels) in perform'
/Users/petrik/Projects/All/_forks/rails/railties/lib/rails/commands/rake/rake_command.rb:22:in `block in perform'
/Users/petrik/Projects/All/_forks/rails/railties/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Users/petrik/Projects/All/_forks/rails/railties/lib/rails/command.rb:52:in `invoke'
/Users/petrik/Projects/All/_forks/rails/railties/lib/rails/commands.rb:18:in `<main>'
/Users/petrik/.gem/ruby/2.7.1/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/petrik/.gem/ruby/2.7.1/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/petrik/.gem/ruby/2.7.1/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/petrik/.gem/ruby/2.7.1/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/petrik/.gem/ruby/2.7.1/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/petrik/Projects/All/_forks/rails/activesupport/lib/active_support/dependencies.rb:332:in `block in require'
/Users/petrik/Projects/All/_forks/rails/activesupport/lib/active_support/dependencies.rb:299:in `load_dependency'
/Users/petrik/Projects/All/_forks/rails/activesupport/lib/active_support/dependencies.rb:332:in `require'
/Users/petrik/Projects/All/_sandbox/rails/bin/rails:9:in `<top (required)>'
/Users/petrik/.gem/ruby/2.7.1/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
/Users/petrik/.gem/ruby/2.7.1/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
/Users/petrik/.gem/ruby/2.7.1/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
/Users/petrik/.gem/ruby/2.7.1/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
/Users/petrik/.gem/ruby/2.7.1/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
/Users/petrik/.gem/ruby/2.7.1/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
/Users/petrik/.gem/ruby/2.7.1/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
/Users/petrik/Projects/All/_sandbox/rails/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
(See full trace by running task with --trace)
3 Likes

Anyone reading this: DHH has indicated elsewhere that he’s open to more aggressive backtrace cleaning. This could be a good first Rails PR for someone!

2 Likes

I’ll see if I can pick this up. I think this first needs a PR for Rake to add a custom error if a task isn’t found.

I’ve opened a PR for Rake: https://github.com/ruby/rake/pull/354

2 Likes