All exceptions — including signals — are caught during an observation
- 主要语言
- Ruby
- 星标
- 7.8k
- 派生
- 505
- PR 合并指标
- 30 天内没有已合并 PR
描述
`observation.rb` does this:
```ruby
def initialize(name, experiment, &block)
...
begin
@value = block.call
rescue Object => e
@exception = e
end
...
end
```
Which is a [well](http://daniel.fone.net.nz/blog/2013/05/28/why-you-should-never-rescue-exception-in-ruby/) [documented](http://www.mikeperham.com/2012/03/03/the-perils-of-rescue-exception/) [anti-pattern](https://robots.thoughtbot.com/rescue-standarderror-not-exception). In particular, it means that any signals (eg. ``) will be treated as-if they were just an error in the candidate code (which usually means logging and ignoring).
Note: There's no difference between `rescue Object` and `rescue Exception` because raising a non-exception (eg. a string) will either raise a `` or a ``.
I think the standard pattern — `rescue StandardError` — is correct here. That will catch everything except `SignalException`s and other things which aren't meant to be dealt-with as part of standard error handling.
Although users could filter-out all non-StandardError Exceptions themselves, this feels like a footgun (since signals will be relatively rare — especially in development — most users won't notice any problems until they happen in production).
贡献指南
调研方向
从 observation.rb 中的 initialize 方法开始,检查 block.call 周围的 rescue。按照要求更改异常处理,使信号不会被当作候选代码错误处理,然后验证标准错误仍会被捕获而不会吞掉信号。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- ruby
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 52/100