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 Android Gradle Plugin namespace support required for React Native 0.73 and backward compatibility with previous versions ([#1044](https://github.com/Instabug/Instabug-React-Native/pull/1044)).
- Fix an issue with unhandled JavaScript crashes being reported as native iOS crashes ([#1054](https://github.com/Instabug/Instabug-React-Native/pull/1054))

## [12.1.0](https://github.com/Instabug/Instabug-React-Native/compare/v12.1.0...v11.14.0)

Expand Down
10 changes: 8 additions & 2 deletions ios/RNInstabug/InstabugCrashReportingBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,29 @@ + (BOOL)requiresMainQueueSetup
IBGCrashReporting.enabled = isEnabled;
}

RCT_EXPORT_METHOD(sendJSCrash:(NSDictionary *)stackTrace) {
RCT_EXPORT_METHOD(sendJSCrash:(NSDictionary *)stackTrace
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
SEL reportCrashWithStackTraceSEL = NSSelectorFromString(@"reportCrashWithStackTrace:handled:");
if ([[Instabug class] respondsToSelector:reportCrashWithStackTraceSEL]) {
[[Instabug class] performSelector:reportCrashWithStackTraceSEL withObject:stackTrace withObject:@(NO)];
}
resolve([NSNull null]);
});
}

RCT_EXPORT_METHOD(sendHandledJSCrash:(NSDictionary *)stackTrace) {
RCT_EXPORT_METHOD(sendHandledJSCrash:(NSDictionary *)stackTrace
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
SEL reportCrashWithStackTraceSEL = NSSelectorFromString(@"reportCrashWithStackTrace:handled:");
if ([[Instabug class] respondsToSelector:reportCrashWithStackTraceSEL]) {
[[Instabug class] performSelector:reportCrashWithStackTraceSEL withObject:stackTrace withObject:@(YES)];
}
resolve([NSNull null]);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/CrashReporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export const setEnabled = (isEnabled: boolean) => {
* @param error Error object to be sent to Instabug's servers
*/
export const reportError = (error: ExtendedError) => {
InstabugUtils.sendCrashReport(error, NativeCrashReporting.sendHandledJSCrash);
return InstabugUtils.sendCrashReport(error, NativeCrashReporting.sendHandledJSCrash);
};
4 changes: 2 additions & 2 deletions src/native/NativeCrashReporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export interface CrashData {

export interface CrashReportingNativeModule extends NativeModule {
setEnabled(isEnabled: boolean): void;
sendJSCrash(data: CrashData | string): void;
sendHandledJSCrash(data: CrashData | string): void;
sendJSCrash(data: CrashData | string): Promise<void>;
sendHandledJSCrash(data: CrashData | string): Promise<void>;
}

export const NativeCrashReporting = NativeModules.IBGCrashReporting;
20 changes: 10 additions & 10 deletions src/utils/InstabugUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorHandlerCallback, Platform } from 'react-native';
import { Platform } from 'react-native';
import parseErrorStackLib, {
ExtendedError,
StackFrame,
Expand Down Expand Up @@ -67,12 +67,12 @@ export const captureJsErrors = () => {

const originalErrorHandler = ErrorUtils.getGlobalHandler();

const instabugErrorHandler: ErrorHandlerCallback = (err) => {
sendCrashReport(err, NativeCrashReporting.sendJSCrash);
const instabugErrorHandler = (err: any, _isFatal?: boolean): Promise<void> => {
return sendCrashReport(err, NativeCrashReporting.sendJSCrash);
};

ErrorUtils.setGlobalHandler((err, isFatal) => {
instabugErrorHandler(err, isFatal);
ErrorUtils.setGlobalHandler(async (err, isFatal) => {
await instabugErrorHandler(err, isFatal);

if (process.env.JEST_WORKER_ID) {
return;
Expand Down Expand Up @@ -104,9 +104,9 @@ export const stringifyIfNotString = (input: unknown) => {
* `sendCrashReport(error, NativeCrashReporting.sendJSCrash);`
*
*/
export function sendCrashReport(
export async function sendCrashReport(
error: ExtendedError,
remoteSenderCallback: (json: CrashData | string) => void,
remoteSenderCallback: (json: CrashData | string) => Promise<void>,
) {
const jsStackTrace = getStackTrace(error);

Expand All @@ -120,10 +120,10 @@ export function sendCrashReport(
};

if (Platform.OS === 'android') {
remoteSenderCallback(JSON.stringify(jsonObject));
} else {
remoteSenderCallback(jsonObject);
return remoteSenderCallback(JSON.stringify(jsonObject));
}

return remoteSenderCallback(jsonObject);
}

export default {
Expand Down