-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
defining a task named `load' would shadow an existing method with that name (ArgumentError) #7
Comments
Do you get the same exception if you try to mirror just that one task? For example:
|
Yes, I reproduced this, both ways. |
Unfortunately, this is going to require a workaround for now. Solving the problem will have implications for the Cape DSL. Capistrano is complaining that we’re creating a recipe that shares the name of a Ruby method. Rake tasks db:fixtures:load and db:schema:load both run afoul of this Capistrano guard because of the existence of Kernel::load in the same scope. I just verified that a Rake task named require would not be able to be mirrored because of the existence of Kernel::require in the same scope. Here’s the workaround. Use the Cape DSL to ignore tasks and namespaces whose names will collide with existing methods.
I’ll probably add a feature to the DSL to allow you to specify a new name for the mirrored task, or possibly a prefix for tasks that collide with existing method names. |
That's not the nicest solution, but it's working for me. Thanks :) |
BTW the above solution does not work with capistrano multistage. The rails_env evaluates to :production changing the line to env['RAILS_ENV'] = rails_env.to_s solves the issue but of course the core problem is not solved Not mirroring Rake task |
@timuckun, I regret to say that I have not used the capistrano-ext gem — I have supported multiple stages through manual Capistrano configuration. Please elaborate on what you believe to be the root of the problem. Thanks in advance. |
The root of the problem seems to be a naming conflict between capistrano-ext and cape. In my case I chose to only mirror specific tasks but I think in the long run you still need to resolve this issue because capistrano-ext is widely used. |
I agree that Cape needs to provide a way to deal gracefully with recipe name collisions. Concerning the collision in question, I’ve just confirmed that although the Rake task db:fixtures:load collides with Kernel::load under Capistrano v2.11.2, there is no such problem under Capistrano v2.13.4. |
I'm having this problem in Capistrano v2.14.1, so it seems it came back. |
The work on an enhanced DSL is nearing completion. Here’s a preview of how you will be able to resolve this issue using the enhanced DSL.
In the above example, all Rake tasks are mirrored, and their recipe names all get the _task suffix tacked onto them. You could rename only specific tasks by writing multiple A Feedback on this is welcome. |
My solution was to namespace my tasks. I prefixed it with a z: so that it would end up on the bottom of the list when I did a rake -T Cape do
each_rake_task do |t|
#only add the tasks that start with z
next unless 'z' == t[:name][0, 1]
begin
mirror_rake_tasks t[:name], :name => 'tim', :roles => :db do |env|
env['RAILS_ENV'] = rails_env.to_s
end
rescue ArgumentError => e
$stderr.puts "Not mirroring Rake task `#{t[:name]}' because #{e.message}"
end
end
end |
Hey @njonsson are you sure this solves the issue? I renamed all tasks but capistrano (version |
@why-el, please paste into this thread the Cape statements you’re using to rename tasks. |
Hey @njonsson sorry I had since reverted to simply defining my tasks manually. What I wrote is exactly what happened but I am actually no longer at the company where this error happened. ;) |
I am having the same issue as @njonsson I'm using your code above. I use namespace :rake_tasks do
Cape do
mirror_rake_tasks do |recipes|
recipes.options[:roles] = :app
recipes.env['RAILS_ENV'] = lambda { rails_env }
# The mirrored Capistrano recipe for a Rake task 'foo' will be named
# 'rake_tasks:foo_task'.
recipes.rename do |rake_task_name|
"#{rake_task_name}_task"
end
end
end
end |
I ended up filtering out tasks I don't want to mirror. I had to change the namespace of my rake tasks as well. It seems the namespace |
I'm using Capistrano and Rake with Rails3 and rake-rails. I've narrowed the error down to happening when it gets to defining the cap task for Rake's
db:fixtures:load
The relevant Cap code is:
The text was updated successfully, but these errors were encountered: