tags:

views:

35

answers:

1

Hi,

Let's say I have a rakefile like this:

file 'file1' => some_dependencies do
  sh 'external tool I do not have control over, which sometimes fail to create the file'
  ???
end

task :default => 'file1' do
  puts "everything's OK"
end

Now if I put nothing in place of ???, I get the OK message, even if the external tool fails to generate file. What is the proper way to informing rake, that 'file1' task has failed and it should abort (hopefully presenting a meaningful message - like which task did fail) - the only think I can think of now is raising an exception there, but that just doesn't seem right.

P.S The tool always returns 0 as exit code.

+1  A: 

Use the fail method. This method takes a string as an argument which is used as the error message displayed at termination of the script. This will also cause the script to return the value 1 to the calling shell. It is documented here and other places.

Richard Cook