github / github/scientist

Ignoring specific exceptions

Đang mở
#67 2 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Ruby
Star
7.8k
Fork
505
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.