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

Avoid overly-general rescue in callback controller #1530

Merged

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Oct 11, 2022

Closes #1527

Still to test, just looking for feedback on the approach.

@@ -35,13 +35,13 @@ class CallbackControllerTest < ActionController::TestCase
end

test "#callback flashes error when omniauth is not present" do
get :callback, params: { shop: "shop" }
Copy link
Contributor Author

@andyw8 andyw8 Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rescue meant these tests were passing, but for the wrong reason. Without the rescue, they failed with:

Error:
ShopifyApp::CallbackControllerTest#test_#callback_flashes_error_in_Spanish:
ArgumentError: missing keywords: :code, :timestamp, :state, :host, :hmac
    test/controllers/callback_controller_test.rb:44:in `block in <class:CallbackControllerTest>'

@andyw8 andyw8 force-pushed the andyw8/avoid-overly-general-rescue-in-callback-controller branch from 5692966 to 7b34a9a Compare October 11, 2022 12:52
rescue
return respond_with_error
rescue => e
if e.class.module_parent == ShopifyAPI::Errors
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no common base for the error classes, this seemed the cleanest way. (It's from ActiveSupport).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach!

I guess the other tricky consideration would be, what if it is an error from the gem?.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's possible here - the code within the rescued block only calls out to ShopifyAPI, and the ShopifyAPI gem has no knowledge of ShopifyApp.

@andyw8 andyw8 requested a review from nelsonwittwer October 11, 2022 12:57
@andyw8 andyw8 mentioned this pull request Oct 14, 2022
4 tasks
@andyw8
Copy link
Contributor Author

andyw8 commented Oct 26, 2022

I think we should get the logging in place before doing this.

@andyw8
Copy link
Contributor Author

andyw8 commented Nov 14, 2022

I plan to change this to emit a deprecation warning instead of raising.

@andyw8 andyw8 force-pushed the andyw8/avoid-overly-general-rescue-in-callback-controller branch from 7b34a9a to a332f41 Compare November 14, 2022 20:06
@andyw8 andyw8 force-pushed the andyw8/avoid-overly-general-rescue-in-callback-controller branch from 7c84257 to 0157633 Compare November 14, 2022 20:50
@andyw8 andyw8 force-pushed the andyw8/avoid-overly-general-rescue-in-callback-controller branch from 0157633 to 6eaaa41 Compare November 14, 2022 21:07
@andyw8 andyw8 marked this pull request as ready for review November 14, 2022 21:07
@andyw8
Copy link
Contributor Author

andyw8 commented Nov 14, 2022

@nelsonwittwer ready for a final review.

@andyw8
Copy link
Contributor Author

andyw8 commented Nov 15, 2022

/shipit

@andyw8 andyw8 merged commit 2f844ef into main Nov 15, 2022
@andyw8 andyw8 deleted the andyw8/avoid-overly-general-rescue-in-callback-controller branch November 15, 2022 17:12
fabriazza pushed a commit to fabriazza/shopify_app that referenced this pull request Feb 1, 2023
* Avoid overly-general rescue in callback controller

* Deprecation error

* Add tests

* Update CHANGELOG

Co-authored-by: Andy Waite <[email protected]>
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.

Avoid overly-general rescue of errors in CallbackController
2 participants