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, ie 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?
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.