Skip to content

fix: android native rejections should be instanceof Error - #44487

Closed
huzhanbo1996 wants to merge 2 commits into
react:mainfrom
huzhanbo1996:p/huzhanbo/rejectErrorAndroid
Closed

fix: android native rejections should be instanceof Error#44487
huzhanbo1996 wants to merge 2 commits into
react:mainfrom
huzhanbo1996:p/huzhanbo/rejectErrorAndroid

Conversation

@huzhanbo1996

Copy link
Copy Markdown

Summary:

fix#44050

Changelog:

[ANDROID] [FIXED] - fix: android native rejections should be instanceof Error

Test Plan:

reject returns Error.

@facebook-github-botfacebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 8, 2024
@huzhanbo1996

huzhanbo1996 commented May 8, 2024

Copy link
Copy Markdown
Author

Hi, @javache

As in #44051, you suggests that a fix from Java to C++. But I found out that same as fix on iOS #41955, we can treat reject on C++.

If we want to fix it from Java, we probably need a Java Error type (currently WritableNativeMap is universal argument for callback), and the argument conversion should support Java Error -> Dynamic -> JSI Object to this specific type. It looks this solution needs huge work.

If you have any other ideas, please let me know.

@facebook-github-botfacebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label May 8, 2024
@analysis-bot

analysis-bot commented May 8, 2024

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a19,495,386-45,446
androidhermesarmeabi-v7an/a--
androidhermesx86n/a--
androidhermesx86_64n/a--
androidjscarm64-v8a22,867,572-44,417
androidjscarmeabi-v7an/a--
androidjscx86n/a--
androidjscx86_64n/a--

Base commit: 54f582f
Branch: main

}

auto createRejectionError(jsi::Runtime& rt, folly::dynamic args) {
DCHECK(args.size() == 1) << "promise reject should has only one argument";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use react_native_assert so we get consistent assert handling

Comment on lines +138 to +139
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: make this an else

Comment on lines +112 to +113
jsError.asObject(rt).setProperty(
rt, propertyName, valueAsObject.getProperty(rt, propertyName));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cache jsError.asObject so we don't repeatedly create a new jsi::Value here


auto propertyNames = valueAsObject.getPropertyNames(rt);
for (size_t i = 0; i < propertyNames.size(rt); ++i) {
auto propertyName = propertyNames.getValueAtIndex(rt, i).asString(rt);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wrap in PropNameID.forString() to avoid doing this conversion twice.

@javache

Copy link
Copy Markdown
Contributor

Looks good overall, just a few nits

@huzhanbo1996

Copy link
Copy Markdown
Author

Looks good overall, just a few nits

Thanks for the advice. Changes updated, PTAL again

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@huzhanbo1996

Copy link
Copy Markdown
Author

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Hi @javache, is the CI check OK?

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@javache merged this pull request in 62cbdbb.

@facebook-github-botfacebook-github-bot added the Merged This PR has been merged. label May 14, 2024
@github-actions

Copy link
Copy Markdown

This pull request was successfully merged by huzhanbo.luc in 62cbdbb.

When will my fix make it into a release? | How to file a pick request?

kosmydel pushed a commit to kosmydel/react-native that referenced this pull request Jun 11, 2024
Summary:
fixreact#44050
## Changelog:
[ANDROID] [FIXED] - fix: android native rejections should be instanceof Error
Pull Request resolved: react#44487
Test Plan: reject returns Error.
Reviewed By: NickGerleman
Differential Revision: D57205131
Pulled By: javache
fbshipit-source-id: a5950481d0c4909be4dbea0b430e75222258ae68
Titozzz pushed a commit that referenced this pull request Jun 18, 2024
Summary:
fix#44050
## Changelog:
[ANDROID] [FIXED] - fix: android native rejections should be instanceof Error
Pull Request resolved: #44487
Test Plan: reject returns Error.
Reviewed By: NickGerleman
Differential Revision: D57205131
Pulled By: javache
fbshipit-source-id: a5950481d0c4909be4dbea0b430e75222258ae68
Titozzz pushed a commit that referenced this pull request Jun 18, 2024
Summary:
fix#44050
## Changelog:
[ANDROID] [FIXED] - fix: android native rejections should be instanceof Error
Pull Request resolved: #44487
Test Plan: reject returns Error.
Reviewed By: NickGerleman
Differential Revision: D57205131
Pulled By: javache
fbshipit-source-id: a5950481d0c4909be4dbea0b430e75222258ae68
This was referenced Jun 28, 2024
@cipolleschicipolleschi mentioned this pull request Jul 22, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.MergedThis PR has been merged.Shared with MetaApplied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android native module rejections are not instanceof Error

4 participants

@huzhanbo1996@analysis-bot@javache@facebook-github-bot