-
-
Notifications
You must be signed in to change notification settings - Fork 763
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
Stop rescuing all exceptions. #2063
Conversation
@@ -178,4 +178,12 @@ def self.const_missing(name) | |||
require MODULES_TO_AUTOLOAD.fetch(name) { return super } | |||
::RSpec.const_get(name) | |||
end | |||
|
|||
module NonPassthroughExceptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat
no idea ... if only we had a bisect feature... :P |
Tried it. Here's the output so far:
|
OK, I figured out the source of the problem.
I'm not sure on what the right fix for this is. We could potentially treat Any thoughts, @rspec/rspec? @SephVelut, as the one who opened #2058, what do you think? |
Good dig into the problem @myronmarston! Testing a process that happens to fork and exit on the same tty - with a stack that contains callbacks to rspec - is definitely a gotcha. You'll wonder why you're getting multiple runs of the tests. But I think its probably an unavoidable gotcha when testing forks. Tracking the pid on the reporter is an interesting idea. But I can also se why
I'm inclined to agree. I suppose even a feature for 'turning off' reporting in subprocess that exits won't be a better solution than simply using Here is my current suggestion. Lets add a note to gotchas and suggest manually rescuing |
|
I'm not sure if we need it for when users are running specs via the I tried removing the Removing the
Mine, too. (Particularly since I've not heard of anyone else running into this gotcha).
What gotchas list do you want a note added to? You linked to capybara. Anyhow, what you suggested made me realize this would work: RSpec.configure do |c|
c.around(:example) do |ex|
begin
ex.run
rescue SystemExit
exit!
end
end
end You could use a hook like this to transform an As for this PR...regardless of if we do anything in particular for the |
I looked a bit more into the
|
fwiw I always wanted
Agree
Legit. |
It's not required to do it twice (or at least it shouldn't be). When you hit In my experience, the 1st ctrl-c does the cleanup exit pretty quickly as long as it's not a large project with lots of cleanup to perform. I just tried it while running Your projects are perhaps just quite large? Or maybe you've hit a genuine bug no one's reported where RSpec isn't able to exit on the first ctrl-c for some reason. |
it's the large projects thing. Actually when I think about it the current behaviour is a good default for most people. |
Yeah, my bad. In any case this thread's existence is probably good enough as I'd like to think most people would eventually conduct a search on the issue page. |
8cada17
to
9672c83
Compare
9672c83
to
3315bf1
Compare
@@ -227,14 +227,14 @@ def run(example_group_instance, reporter) | |||
rescue Pending::SkipDeclaredInExample | |||
# no-op, required metadata has already been set by the `skip` | |||
# method. | |||
rescue Exception => e | |||
rescue Support::AllExceptionsExceptOnesWeMustNotRescue => e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why, but somehow this change causes a failure for this cucumber scenario on 1.8.7:
https://travis-ci.org/rspec/rspec-core/jobs/77979590
If I change this back to Exception
that passes. Makes absolutely no sense to me :(.
Anyone got any ideas why?
8cfd75e
to
bfea12d
Compare
We do want to generally rescue `Exception` and any subclasses but there are a few exceptions we should not rescue. For example, if we rescue `SystemExit`, it prevents `exit` from exiting. Part of #2058.
bfea12d
to
f2d40c1
Compare
This is finally green! Anyone from @rspec/rspec want to do a final review before I merge? |
set_exception(e) | ||
ensure | ||
run_after_example | ||
end | ||
end | ||
end | ||
rescue Exception => e | ||
rescue Support::AllExceptionsExceptOnesWeMustNotRescue => e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Namespaced here but not above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one above is RSpec::Core::AllExceptionsExcludingDangerousOnesOnRubiesThatAllowIt
, not a constant from the RSpec::Support
namespace. See the definition and comment below. Yes, it's weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only this one? Wut!?
LGTM |
Stop rescuing all exceptions.
Stop rescuing all exceptions.
We do want to generally rescue
Exception
andany subclasses but there are a few exceptions
we should not rescue. For example, if we rescue
SystemExit
, it preventsexit
from exiting.Attempted fix for #2058.
Note that the spec I added failed without these changes and passes with it...but there are some other weird effects that I do not understand:
I'm a bit at a loss for what's causing this. Anyone from @rspec/rspec got any ideas?