Forced ruby ​​to hide the reverse side from exclusion

I perform some common tasks with Rakefile, for example, compiling, linking, etc.

If compilation fails, ruby ​​shows the full back trace in which the task error occurs, but it is really useless to me, even more: this return line hides compilation errors.

$ rake
mkdir -p build
llvm-as source/repl.ll -o build/repl.bc
llvm-as: source/repl.ll:6:22: error: expected value token
  call i32 @fputc(i8 'x', i32 0)
                 ^
rake aborted!
Command failed with status (1): [llvm-as source/repl.ll -o build/repl.bc...]
/usr/local/lib/ruby/1.9.1/rake.rb:993:in `block in sh'
/usr/local/lib/ruby/1.9.1/rake.rb:1008:in `call'
/usr/local/lib/ruby/1.9.1/rake.rb:1008:in `sh'
/usr/local/lib/ruby/1.9.1/rake.rb:1092:in `sh'
...

How to hide everything after "rake aborted!"

+3
source share
1 answer

It seems that you are using the "sh" command in the rake task to start the compiler. In this case, you must catch a RuntimeError to get this error. Something like that:

task "foo" do
  begin
    sh "bar"
  rescue RuntimeError => e
    puts e.message
    exit(1)
  end
end
+5
source

All Articles