Search code examples
ruby-on-railsrake

How can I disable the trace in rake tasks?


I'm not sure when this started, but whenever I run a rake task in Rails:

$ rake routes

Before it prints the routes, it shows the trace:

** Invoke routes (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute routes

I thought those invoke/execute statements would only appear if I added --trace to my command, but it happens for all of my rake tasks (db create/migrate, Capistrano, etc.)

Is there a way to disable the trace functionality? Is there a configuration file in Rails that might be enabling trace that I'm unaware of?


Solution

  • The problem has been tracked down to a custom gem that implements a Capistrano Plugin. The gem allows for a different version control system to be used with Capistrano other than the ones they provide (Git, SVN, etc.).

    The ultimate issue was that capistrano/lib/capistrano/all.rb has this line:

    Rake.application.options.trace = true
    

    This file was being loaded with the Capistrano Plugins, but the default ones are not required until used in the Capfile. When we created a custom gem with a new plugin, we simply added the new gem to our application's Gemfile, which loads the files by default. So our plugin file looked like this:

    # custom_gem/lib/capistrano/scm/custom_vc.rb
    require 'capistrano/scm/plugin'
    class Capistrano::SCM::CustomVC < Capistarno::SCM::Plugin
      # ... Mimic the capistrano/lib/capistrano/scm/git.rb in the Capistrano gem.
    end
    

    The top line that requires capistrano/scm/plugin was ultimately requiring the capistrano-lib/capistrano/all.rb that was setting trace to be on for all Rake tasks.

    The solution was to simply add require: false to our Gemfile for the custom gem.

    # Gemfile
    group :development do
      gem 'capistrano_custom_vc', require: false
    end