开发者

How to explicitly fail a task in ruby rake?

开发者 https://www.devze.com 2023-01-16 17:48 出处:网络
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\'

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开发者_StackOverflow社区 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.


Use the raise or fail method as you would for any other Ruby script (fail is an alias for raise). This method takes a string or exception 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.


You can use abort("message") to gracefully fail rake task.

It will print message to stdout and exit with code 1.

Exit code 1 is a failure in Unix-like systems.

See Kernel#abort for details.

0

精彩评论

暂无评论...
验证码 换一张
取 消