强制红宝石在异常时隐藏回溯 [英] Force ruby to hide backtrace on exception

查看:143
本文介绍了强制红宝石在异常时隐藏回溯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Rakefile做一些常规任务,例如编译,链接等.

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

当编译失败时,ruby会显示发生任务错误的完整回溯,但对我来说真的没用,甚至更多:此回溯会隐藏编译错误.

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!" ?

推荐答案

似乎您在rake任务中使用"sh"命令来启动编译器.在这种情况下,您应该捕获RuntimeError,以获取此错误.像这样:

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

这篇关于强制红宝石在异常时隐藏回溯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆