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

Allow rescue from non-StandardError exceptions to use default error handling #1754

Merged
merged 1 commit into from
Mar 27, 2018

Conversation

Jelkster
Copy link
Contributor

@Jelkster Jelkster commented Mar 27, 2018

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 and rescuable? logic, with some minor modifications to account for Exception being rescued instead of StandardError. This meant that the additional rescue 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 simply rescue_from Exception. The same as you can rescue_from StandardError for rescue_from :all.

Copy link
Member

@dm1try dm1try left a 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

@dm1try
Copy link
Member

dm1try commented Mar 27, 2018

we deprecate the use of :all so this additional option is probably not necessary, as you can simply rescue_from Exception. The same as you can rescue_from StandardError for rescue_from :all

yep, all adds ambiguity (as I mentioned in related issue) but it's so "sugar")
my point is that a user should not waste time to resolve this using README as he could just use his Ruby knowledge.

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

@Jelkster Jelkster Mar 27, 2018

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

Copy link
Member

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?

Copy link
Contributor Author

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 🤦‍♂️

@dblock
Copy link
Member

dblock commented Mar 27, 2018

Stepping back I think :all is bad all around. I am down with deprecating it completely and forcing users to do rescue_from Exception or rescue_from StandardError with a major version bump. That can be done in a separate PR.

Therefore, before we add rescue_from :exception, are you are you saying @Jelkster that we cannot make a non-block version without introducing a symbol sugar? Otherwise I think we just want to fix that ability instead of adding :exception support.

@Jelkster
Copy link
Contributor Author

Jelkster commented Mar 27, 2018

@dblock, no, this code can handle non-blocks no problem without the symbol sugar. I was in the middle of implementing rescue_from :exception before @dm1try addressed the issue, so I just left it in there in case you wanted to take a look at the end result. It seems like we are all realizing the lack of need (and clarity) for the sugar.

@dblock
Copy link
Member

dblock commented Mar 27, 2018

So should we just close this and focus on deprecating :all? Maybe we still want README updates?

@Jelkster
Copy link
Contributor Author

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.

@dblock
Copy link
Member

dblock commented Mar 27, 2018

Makes sense, looking forward to an update @Jelkster. Thanks for hanging in there!

@Jelkster Jelkster changed the title Add rescue_from :exception to truly rescue from all exceptions Allow rescue from non-StandardError exceptions to use default error handling Mar 27, 2018
@Jelkster
Copy link
Contributor Author

@dblock updated!

@dblock dblock merged commit a68d36d into ruby-grape:master Mar 27, 2018
@dblock
Copy link
Member

dblock commented Mar 27, 2018

Great work @Jelkster. Want to tackle the deprecation of :all next?

@Jelkster
Copy link
Contributor Author

I'm actually on vacation this week, but I can definitely take a stab when it's over.

@dblock
Copy link
Member

dblock commented Mar 29, 2018

What do we pay you for @Jelkster :)

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

Successfully merging this pull request may close these issues.

3 participants