开发者

Force ruby to hide backtrace on exception

I do some usual tasks with Rakefile, such as compilation, linking, etc.

When compilation fails ruby shows full backtrace in which task error happen, but it's really useless for me, even more: this backtrace hides compilation errors.

$ rake
mkdir -p build
llvm-as source/repl.ll -o build/repl.bc
llvm-as: s开发者_开发技巧ource/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 all after "rake aborted!" ?


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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜