Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignoring specific exceptions #67

Open
andreas opened this issue Mar 16, 2017 · 2 comments
Open

Ignoring specific exceptions #67

andreas opened this issue Mar 16, 2017 · 2 comments

Comments

@andreas
Copy link

andreas commented Mar 16, 2017

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:

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:

# 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?

@jbarnette
Copy link
Contributor

@andreas 👋 Doing some long-delayed issue gardening. I like this idea, but I'm wondering how to implement it in a backwards-compatible way. We might need to do this w/a major version bump, although even there I'm reluctant to break the interface without a deprecation period.

@andreas
Copy link
Author

andreas commented Aug 11, 2017

Ideas for backwards-compatible solutions (none of them particularly clean):

  • ignore could pass more arguments to the block, which is backwards-compatible assuming clients use a proc.
  • Add a new method ignore2 which receives observation objects instead of values.
  • Pass a custom nil-value as observation value to ignore if an exception is raised. This special nil-value should expose the exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants