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

Add missing catch #1407

Merged
merged 2 commits into from
Jul 4, 2023
Merged

Add missing catch #1407

merged 2 commits into from
Jul 4, 2023

Conversation

robinsoncol
Copy link
Contributor

@robinsoncol robinsoncol commented Jun 27, 2023

No description provided.

@request-info
Copy link

request-info bot commented Jun 27, 2023

We would appreciate it if you could provide us with more info about this issue/pr! :smiley

@request-info request-info bot added the needs-more-info Needs more info regarding what this issue/pr achieves label Jun 27, 2023
@matheusmichels
Copy link

This is a pretty important fix, since the Share.open() promise will never get resolved if the native promise is rejected
@jgcmarins @MateusAndrade @mikehardy

@MateusAndrade
Copy link
Collaborator

mikehardy
mikehardy previously approved these changes Jun 30, 2023
Copy link
Collaborator

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

This is pretty difficult to follow (not your fault!) because of the nesting, but I carefully went through and counted open/close parentheses and this is right where the native open/then structure could have a catch, and there is no catch

What I don't understand:

Prior to this PR the native could throw without an immediate catch, meaning it should bubble up to the enclosing context, which is a then on requireAndAskPermissions

According to this info about exceptions thrown while in a then block, https://stackoverflow.com/a/38690864/9910298 - that should go to the next catch.

So I don't understand why the enclosing catch doesn't already function the same as what you have?

That said, the catch you have added is doing the same thing the enclosing one is doing, and is not capable of doing anything wrong as there is no logic between the new catch and the existing final catch that will be missed or similar, so I cannot see how this would harm, and you indicate this fixes a failure to resolve for you

So I'm +1 on it, with the final criteria being: you have tested this and it fixes something for you :-)

Final thought: should the reject's be return reject, similar to the return resolve ?

@robinsoncol
Copy link
Contributor Author

robinsoncol commented Jun 30, 2023

@mikehardy @MateusAndrade @jgcmarins The error isn't propagating because the promise returned by NativeRNShare.open(...).then(...) isn't being returned. If you return NativeRNShare.open(...).then(...) you won't need the fix above, but both solutions solve the same issue.

There seems to be a lot unnecessary promise nesting. It's best to merge this PR to fix this issue and I'll submit another PR to clean up the code.

@robinsoncol
Copy link
Contributor Author

robinsoncol commented Jun 30, 2023

Copy link
Collaborator

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

I'm +1 on this, for what it's worth, and I appreciate the explanations + discussion, thanks!

@MateusAndrade MateusAndrade enabled auto-merge (squash) July 4, 2023 07:42
@MateusAndrade
Copy link
Collaborator

There is an iOS build error, but it's not related to this PR. So, it should be ok to merge it. Thanks @robinsoncol !

@MateusAndrade MateusAndrade merged commit 20b1d20 into react-native-share:main Jul 4, 2023
2 of 3 checks passed
MateusAndrade pushed a commit that referenced this pull request Jul 4, 2023
* Add missing catch

* chore: apply lint
MateusAndrade pushed a commit that referenced this pull request Jul 4, 2023
## [9.1.1](v9.1.0...v9.1.1) (2023-07-04)

### Bug Fixes

* **promise:** Add missing catch ([#1407](#1407)) ([b9cf25d](b9cf25d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-more-info Needs more info regarding what this issue/pr achieves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants