Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force ruby to hide backtrace on exception

Tags:

rakefile

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: 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 all after "rake aborted!" ?

like image 864
Vladimir Gordeev Avatar asked Feb 25 '23 18:02

Vladimir Gordeev


1 Answers

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
like image 134
valo Avatar answered Jun 09 '23 08:06

valo