Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed

- Fix an issue with `Instabug.init` on Android causing the app to crash while trying to get the current `Application` instance through the current activity which can be `null` in some cases by utilizing the React context instead ([#1069](https://github.com/Instabug/Instabug-React-Native/pull/1069)).
- Fix an issue with unhandled JavaScript crashes not getting linked with the current session causing inaccurate session metrics ([#1071](https://github.com/Instabug/Instabug-React-Native/pull/1071)).

## [12.2.0](https://github.com/Instabug/Instabug-React-Native/compare/v12.2.0...v12.1.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.instabug.reactlibrary.utils.InstabugUtil.getMethod;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
Expand All @@ -15,6 +16,7 @@
import java.lang.reflect.Method;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class RNInstabugCrashReportingModule extends ReactContextBaseJavaModule {

Expand Down Expand Up @@ -55,12 +57,19 @@ public void run() {
* Send unhandled JS error object
*
* @param exceptionObject Exception object to be sent to Instabug's servers
* @param promise This makes sure that the RN side crashes the app only after the Android SDK
* finishes processing/handling the crash.
*/
@ReactMethod
public void sendJSCrash(final String exceptionObject) {
public void sendJSCrash(final String exceptionObject, final Promise promise) {
try {
JSONObject jsonObject = new JSONObject(exceptionObject);
sendJSCrashByReflection(jsonObject, false);
sendJSCrashByReflection(jsonObject, false, new Runnable() {
@Override
public void run() {
promise.resolve(null);
}
});
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -75,13 +84,13 @@ public void sendJSCrash(final String exceptionObject) {
public void sendHandledJSCrash(final String exceptionObject) {
try {
JSONObject jsonObject = new JSONObject(exceptionObject);
sendJSCrashByReflection(jsonObject, true);
sendJSCrashByReflection(jsonObject, true, null);
} catch (Exception e) {
e.printStackTrace();
}
}

private void sendJSCrashByReflection(final JSONObject exceptionObject, final boolean isHandled) {
private void sendJSCrashByReflection(final JSONObject exceptionObject, final boolean isHandled, @Nullable final Runnable onComplete) {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
public void run() {
Expand All @@ -97,6 +106,10 @@ public void run() {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} finally {
if (onComplete != null) {
onComplete.run();
}
}
}
});
Expand Down
9 changes: 1 addition & 8 deletions src/utils/InstabugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,7 @@ export const captureJsErrors = () => {
if (process.env.JEST_WORKER_ID) {
return;
}

if (Platform.OS === 'android') {
setTimeout(() => {
originalErrorHandler(err, isFatal);
}, 500);
} else {
originalErrorHandler(err, isFatal);
}
originalErrorHandler(err, isFatal);
});
};

Expand Down