获取 ruby 警告的堆栈跟踪信息
我在 ruby 1.9 中遇到了一些关于 UTF 字符串的奇怪错误。 ruby 通常会抱怨这样的事情:
warning: regexp match /.../n against to UTF-8 string
我希望能够在警告上显示完整的堆栈跟踪,或者应用某种可以覆盖默认警告功能的猴子补丁。我该怎么做?
I've been running into some strange errors with UTF strings in ruby 1.9. Often ruby will complain on something like this:
warning: regexp match /.../n against to UTF-8 string
I'd like to be able to show a full stack trace on a warning, or apply some kind of monkey patch that i can override the default warning functionality. How would i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果警告来自 Ruby 代码(而不是本机 C),您可以覆盖
Warning#warn
,然后警告变为异常,您当然会得到回溯:感谢:你能让 ruby 将警告视为错误吗?
If the warning comes from Ruby code(instead of native C), you can overwrite
Warning#warn
, then the warning becomes an exception you will get the backtrace of course:Thanks to: Can you ask ruby to treat warnings as errors?
尝试
$DEBUG = true
。这至少会导致一些警告变成错误。Try
$DEBUG = true
. That will cause at least some warnings to turn into errors.