-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Allow rescue from non-StandardError
exceptions to use default error handling
#1754
Conversation
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 code looks good to me, thank you!
as regards to the new :exception
feature, I've never had to rescue from Exception
😎 so I have no strong feelings about this.
@dblock your turn
yep, |
@@ -1,7 +1,13 @@ | |||
require 'spec_helper' | |||
|
|||
describe Grape::Xml do | |||
it 'uses multi_xml' do | |||
expect(Grape::Xml).to eq(::MultiXml) | |||
if Object.const_defined? :MultiXml |
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.
This change should not be required, the integration spec is specifically for mutli_xml, so it should never be in that else
.
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.
That makes sense about not ever being in the else
since this is for multi_xml so I'll definitely remove that, but if I don't check for the presence of the constant, this is the only spec that fails for me locally on my ubuntu VM.
Failures:
1) ActiveSupport::XmlMini uses multi_xml
Failure/Error: expect(Grape::Xml).to eq(::MultiXml)
NameError:
uninitialized constant MultiXml
# ./spec/integration/multi_xml/xml_spec.rb:6:in `block (2 levels) in <top (required)>'
Finished in 0.00072 seconds (files took 1.34 seconds to load)
1 example, 1 failure
Ref: /~https://github.com/ruby-grape/grape/blob/master/lib/grape/util/xml.rb
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.
Run specs with rake
, I think we cleverly exclude those as needed and run them with their own bundle?
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.
Ahh, ok, I was running bundle exec rspec
🤦♂️
Stepping back I think Therefore, before we add |
@dblock, no, this code can handle non-blocks no problem without the symbol sugar. I was in the middle of implementing |
So should we just close this and focus on deprecating |
This PR actually added the ability to handle non-blocks (this test fails without it), so I think we'll still want that piece. I can convert this into a fix instead of a feature. |
1621471
to
42866b7
Compare
Makes sense, looking forward to an update @Jelkster. Thanks for hanging in there! |
rescue_from :exception
to truly rescue from all exceptionsStandardError
exceptions to use default error handling
722c189
to
e2e6bd9
Compare
@dblock updated! |
Great work @Jelkster. Want to tackle the deprecation of |
I'm actually on vacation this week, but I can definitely take a stab when it's over. |
What do we pay you for @Jelkster :) |
This continues to address issues discussed in #1713 and #1745.
@dm1try recently added the ability to explicitly rescue non-StandardError exceptions but I found that his solution required a block to be provided in order to handle exceptions or else it would raise an error due to no handler being found. This PR corrects that by re-using the existing
find_handler
andrescuable?
logic, with some minor modifications to account forException
being rescued instead ofStandardError
. This meant that the additionalrescue Exception
block could go away completely.Edit: I forgot that @dm1try recommended we deprecate the use of
:all
so this additional option (rescue_from :exception
- removed from PR after further discussion) is probably not necessary, as you can simplyrescue_from Exception
. The same as you canrescue_from StandardError
forrescue_from :all
.