tags:

views:

35

answers:

1

I have a number of file tasks in my Rakefile which look like

file 'task1' => 'dep' do
  sh "some command"
end

There's also

task :start => :next
task :last => :dep2

I was wondering if there was a way of rescuing it on the top level, i.e. to say

begin
  task :last => :dep2
rescue
  # do something
end

rather than in every file task do

file 'task1' => 'dep' do
  begin
    sh "some command"
  rescue
    # do something
  end
end

Is it possible?

+1  A: 

No, but you can define a custom method to simplify your tasks.

def safe_task(&block)
  yield
rescue
  # do something
end

file 'task1' => 'dep' do
  safe_task do
    sh "some command"
  end
end

Also, remember that is :task2 depends on :task1 and :task1 can raise an exception, you should handle the error in :task1, not in :task2.

Simone Carletti