Skip to content

Commit

Permalink
Use new getCanonicalName and getMessage methods exposed by fbjni (#37879
Browse files Browse the repository at this point in the history
)

Summary:
When a new version of `fbjni` is released, we can simplify `getName` and `getMessage` calls on throwables.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[ANDROID] [CHANGED] - Use new `getCanonicalName` and `getMessage` methods exposed by `fbjni`

Pull Request resolved: #37879

Test Plan: facebookincubator/fbjni#78

Reviewed By: cortinico

Differential Revision: D46966561

Pulled By: javache

fbshipit-source-id: f30720a30146cf8fe5125336435a1512063c253d
  • Loading branch information
krystofwoldrich authored and facebook-github-bot committed Jun 23, 2023
1 parent c34aabb commit 6c729ac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/react-native/ReactAndroid/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ANDROIDX_AUTOFILL_VERSION=1.1.0
ANDROIDX_TEST_VERSION=1.1.0
ANDROIDX_TRACING_VERSION=1.1.0
ASSERTJ_VERSION=3.21.0
FBJNI_VERSION=0.3.0
FBJNI_VERSION=0.4.0
FRESCO_VERSION=2.5.0
INFER_ANNOTATIONS_VERSION=0.18.0
JAVAX_INJECT_VERSION=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ android {
}

dependencies {
implementation("com.facebook.fbjni:fbjni:0.3.0")
implementation("com.facebook.fbjni:fbjni:0.4.0")
implementation("com.facebook.soloader:soloader:0.10.4")
implementation("com.facebook.yoga:proguard-annotations:1.19.0")
implementation("androidx.annotation:annotation:1.3.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,9 @@ jsi::JSError convertThrowableToJSError(
}

jsi::Object cause(runtime);
auto getName = throwable->getClass()
->getClass()
->getMethod<jni::local_ref<jni::JString>()>("getName");
auto getMessage =
throwable->getClass()->getMethod<jni::local_ref<jni::JString>()>(
"getMessage");
auto message = getMessage(throwable)->toStdString();
cause.setProperty(
runtime, "name", getName(throwable->getClass())->toStdString());
auto name = throwable->getClass()->getCanonicalName()->toStdString();
auto message = throwable->getMessage()->toStdString();
cause.setProperty(runtime, "name", name);
cause.setProperty(runtime, "message", message);
cause.setProperty(runtime, "stackElements", std::move(stackElements));

Expand Down

0 comments on commit 6c729ac

Please sign in to comment.