github / github/scientist

Ignoring specific exceptions

Open
#67 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Ruby
Stars
7.8k
Forks
505
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

Open the contributing guide

Research direction

Start at the Scientist::Experiment entry points used by `use`, `try`, and `ignore`, then trace how observation values and exceptions are passed into the ignore block. Done means ignore receives observation objects for both control and candidate, allowing exception inspection without sentinel values; preserve the behavior shown in the proposed example.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.