Ignoring specific exceptions
- 主要语言
- Ruby
- 星标
- 7.8k
- 派生
- 505
- PR 合并指标
- 30 天内没有已合并 PR
描述
Currently observation _values_ and not _observation objects_ are being passed to `ignore`. This means it's not possible to ignore transient exceptions that occur in either candidate or control. When an exception occurs, `nil` is passed as value to `ignore` for that behavior.
Example:
```ruby
e = Scientist::Experiment.new "foo"
e.use { rand > 0.001 ? 42 : raise SomeConnectionTimedOut.new }
e.try { rand > 0.001 ? 42 : raise SomeConnectionTimedOut.new }
e.ignore do |control, candidate|
# control/candidate is nil if exception occurred in that behavior
end
```
It would be great if `ignore` received an observation object instead of only the observation value. That would allow examining the exception value.
Example:
```ruby
# Proposed behavior! This is currently not possible.
ignore do |control, candidate|
control.exception.is_a?(SomeConnectionTimedOut) ||
candidate.exception.is_a?(SomeConnectionTimedOut)
end
```
I currently work around the above issue by rescuing inside `try`/`use` and return a sentinel value -- it's a terrible hack though. Would you accept a PR implementing this?
贡献指南
调研方向
从 `use`、`try` 和 `ignore` 使用的 Scientist::Experiment 入口点开始,然后跟踪观测值和异常如何传递到 ignore 块中。完成标准是 ignore 能够接收 control 和 candidate 两者的观测对象,从而无需哨兵值即可检查异常;保留提议示例中展示的行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- ruby
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100