Skip to content
Open
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
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# Changelog
## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v16.0.3...dev)

### Added

- Add support for chaining errors . ([#1417](https://github.com/Instabug/Instabug-React-Native/pull/1417))

## [16.0.3](https://github.com/Instabug/Instabug-React-Native/compare/v16.0.3...dev)

### Changed

- Bump Instabug iOS SDK to v16.0.3 ([#1452](https://github.com/Instabug/Instabug-React-Native/pull/1452)). [See release notes](https://github.com/Instabug/Instabug-iOS/releases/tag/16.0.3).

## [16.0.1](https://github.com/Instabug/Instabug-React-Native/compare/v16.0.0...dev)

### Fixed

- Reading `INSTABUG_APP_TOKEN` when upload sourcemap file ([#1448](https://github.com/Instabug/Instabug-React-Native/pull/1448))

## [16.0.0](https://github.com/Instabug/Instabug-React-Native/compare/v15.0.3...dev)

Expand Down
9 changes: 2 additions & 7 deletions android/sourcemaps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,17 @@ Task createUploadSourcemapsTask(String flavor, String defaultVersionName, String
def appProject = project(':app')
def appDir = appProject.projectDir
def sourceMapFile = getSourceMapFile(appDir, flavor,task)
println "✅ Resolved sourcemap file path: ${sourceMapFile.absolutePath}"

def jsProjectDir = rootDir.parentFile
def instabugDir = new File(['node', '-p', 'require.resolve("instabug-reactnative/package.json")'].execute(null, rootDir).text.trim()).getParentFile()

def tokenJsFile = new File(instabugDir, 'scripts/find-token.js')
def inferredToken = executeNodeScript(tokenJsFile, jsProjectDir)
def appToken = resolveVar('App Token', 'INSTABUG_APP_TOKEN', inferredToken)

if (!inferredToken) {
if (!appToken) {
throw new GradleException("❌ Unable to infer Instabug token from script: ${tokenShellFile.absolutePath}")
}

def appToken = resolveVar('App Token', 'INSTABUG_APP_TOKEN', inferredToken)

def versionName = resolveVar('Version Name', 'INSTABUG_VERSION_NAME', defaultVersionName)
def versionCode = resolveVar('Version Code', 'INSTABUG_VERSION_CODE', defaultVersionCode)

Expand All @@ -77,8 +74,6 @@ Task createUploadSourcemapsTask(String flavor, String defaultVersionName, String
} catch (exception) {
project.logger.error "Failed to upload source map file.\n" +
"Reason: ${exception.message}"
throw exception

}
}
}
Expand Down
10 changes: 5 additions & 5 deletions examples/default/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PODS:
- hermes-engine (0.75.4):
- hermes-engine/Pre-built (= 0.75.4)
- hermes-engine/Pre-built (0.75.4)
- Instabug (16.0.2)
- Instabug (16.0.3)
- instabug-reactnative-ndk (0.1.0):
- DoubleConversion
- glog
Expand Down Expand Up @@ -1625,8 +1625,8 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- RNInstabug (16.0.0):
- Instabug (= 16.0.2)
- RNInstabug (16.0.3):
- Instabug (= 16.0.3)
- React-Core
- RNReanimated (3.16.1):
- DoubleConversion
Expand Down Expand Up @@ -2022,7 +2022,7 @@ SPEC CHECKSUMS:
Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a
GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac
hermes-engine: ea92f60f37dba025e293cbe4b4a548fd26b610a0
Instabug: 125f729dea4e4a43e815ae06f9db0332e2a5fd60
Instabug: b6290ceceb5d98966aa6f10fbd7970026a916f65
instabug-reactnative-ndk: d765ac289d56e8896398d02760d9abf2562fc641
OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74
RCT-Folly: 4464f4d875961fce86008d45f4ecf6cef6de0740
Expand Down Expand Up @@ -2090,7 +2090,7 @@ SPEC CHECKSUMS:
ReactCommon: 6a952e50c2a4b694731d7682aaa6c79bc156e4ad
RNCClipboard: 2821ac938ef46f736a8de0c8814845dde2dcbdfb
RNGestureHandler: 511250b190a284388f9dd0d2e56c1df76f14cfb8
RNInstabug: f06cf043f071311456d3ad14b4f9da628f2cd29b
RNInstabug: 0b04c724acc081f0da864470f4f296dfc5c933ca
RNReanimated: f42a5044d121d68e91680caacb0293f4274228eb
RNScreens: c7ceced6a8384cb9be5e7a5e88e9e714401fd958
RNSVG: 8b1a777d54096b8c2a0fd38fc9d5a454332bbb4d
Expand Down
30 changes: 30 additions & 0 deletions examples/default/src/screens/CrashReportingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ export const CrashReportingScreen: React.FC = () => {
throw error;
}
}

function throwUnhandledChainingException(error: Error, isPromise: boolean = false) {
const appName = 'Instabug Test App';
const rejectionType = isPromise ? 'Promise Rejection ' : '';
const errorMessage = `Unhandled ${rejectionType}${error.name} from ${appName}`;

if (!error.message) {
console.log(`IBG-CRSH | Error message: ${error.message}`);
error.message = errorMessage;
}

if (isPromise) {
console.log('IBG-CRSH | Promise');
Promise.reject(error).then(() =>
Alert.alert(`Promise Rejection Crash report for ${error.name} is Sent!`),
);
} else {
try {
throw ReferenceError();
} catch (e) {
error.cause = e;
throw error;
}
}
}

const [isEnabled, setIsEnabled] = useState(false);

const [userAttributeKey, setUserAttributeKey] = useState('');
Expand Down Expand Up @@ -216,6 +242,10 @@ export const CrashReportingScreen: React.FC = () => {
title="Throw Unhandled Syntax Exception"
onPress={() => throwUnhandledException(new SyntaxError())}
/>
<ListTile
title="Throw Unhandled Chaining Exception"
onPress={() => throwUnhandledChainingException(new SyntaxError('level 1 SyntaxError'))}
/>
<ListTile
title="Throw Unhandled Range Exception"
onPress={() => throwUnhandledException(new RangeError())}
Expand Down
2 changes: 1 addition & 1 deletion ios/native.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$instabug = { :version => '16.0.2' }
$instabug = { :version => '16.0.3' }

def use_instabug! (spec = nil)
version = $instabug[:version]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "instabug-reactnative",
"description": "React Native plugin for integrating the Instabug SDK",
"version": "16.0.0",
"version": "16.0.3",
"author": "Instabug (https://instabug.com)",
"repository": "github:Instabug/Instabug-React-Native",
"homepage": "https://www.instabug.com/platforms/react-native",
Expand Down
11 changes: 11 additions & 0 deletions src/native/NativeCrashReporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ export interface CrashData {
os: (typeof Platform)['OS'];
platform: 'react_native';
exception: StackFrame[];
cause_crash?: CauseCrashData;
}

export interface CauseCrashData {
message: string;
e_message: string;
e_name: string;
exception: StackFrame[];
cause_crash?: CauseCrashData;
}

export interface CrashReportingNativeModule extends NativeModule {
setEnabled(isEnabled: boolean): void;

sendJSCrash(data: CrashData | string): Promise<void>;

sendHandledJSCrash(
Expand All @@ -23,6 +33,7 @@ export interface CrashReportingNativeModule extends NativeModule {
fingerprint?: string | null,
nonFatalExceptionLevel?: NonFatalErrorLevel | null,
): Promise<void>;

setNDKCrashesEnabled(isEnabled: boolean): Promise<void>;
}

Expand Down
19 changes: 18 additions & 1 deletion src/utils/InstabugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import parseErrorStackLib, {
import type { NavigationState as NavigationStateV5, PartialState } from '@react-navigation/native';
import type { NavigationState as NavigationStateV4 } from 'react-navigation';

import type { CrashData } from '../native/NativeCrashReporting';
import type { CauseCrashData, CrashData } from '../native/NativeCrashReporting';
import { NativeCrashReporting } from '../native/NativeCrashReporting';
import type { NetworkData } from './XhrNetworkInterceptor';
import { NativeInstabug } from '../native/NativeInstabug';
Expand Down Expand Up @@ -59,6 +59,23 @@ export const getCrashDataFromError = (error: Error) => {
platform: 'react_native',
exception: jsStackTrace,
};
// Recursively attach inner_crash objects (up to 3 levels)
let currentError: any = error;
let level = 0;
let parentCrash: CauseCrashData | CrashData = jsonObject;
while (currentError.cause && level < 3) {
const cause = currentError.cause as Error;
const innerCrash: CauseCrashData = {
message: `${cause.name} - ${cause.message}`,
e_message: cause.message,
e_name: cause.name,
exception: getStackTrace(cause),
};
parentCrash.cause_crash = innerCrash;
parentCrash = innerCrash;
currentError = cause;
level++;
}
return jsonObject;
};

Expand Down
59 changes: 59 additions & 0 deletions test/utils/InstabugUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,65 @@ describe('Instabug Utils', () => {
NonFatalErrorLevel.error,
);
});
it('getCrashDataFromError should include one level of cause crash', () => {
const causeError = new TypeError('Cause error');
const rootError = new Error('Root error');
(rootError as any).cause = causeError;

const crashData = InstabugUtils.getCrashDataFromError(rootError);
const jsStackTraceRootError = InstabugUtils.getStackTrace(rootError);
const jsStackTraceCauseError = InstabugUtils.getStackTrace(causeError);

expect(crashData.message).toBe('Error - Root error');
expect(crashData.e_message).toBe('Root error');
expect(crashData.e_name).toBe('Error');
expect(crashData.platform).toBe('react_native');
expect(crashData.exception).toEqual(jsStackTraceRootError);
expect(crashData.cause_crash).toBeDefined();
expect(crashData.cause_crash?.message).toBe('TypeError - Cause error');
expect(crashData.cause_crash?.e_name).toBe('TypeError');
expect(crashData.cause_crash?.exception).toEqual(jsStackTraceCauseError);
});

it('getCrashDataFromError should include up to 3 levels of cause crash', () => {
const errorLevel3 = new Error('Third level error');
const errorLevel2 = new Error('Second level error');
const errorLevel1 = new Error('First level error');
const rootError = new Error('Root error');

(errorLevel2 as any).cause = errorLevel3;
(errorLevel1 as any).cause = errorLevel2;
(rootError as any).cause = errorLevel1;

const crashData = InstabugUtils.getCrashDataFromError(rootError);

expect(crashData.message).toBe('Error - Root error');
expect(crashData.cause_crash?.message).toBe('Error - First level error');
expect(crashData.cause_crash?.cause_crash?.message).toBe('Error - Second level error');
expect(crashData.cause_crash?.cause_crash?.cause_crash?.message).toBe(
'Error - Third level error',
);
expect(crashData.cause_crash?.cause_crash?.cause_crash?.cause_crash).toBeUndefined();
});

it('getCrashDataFromError should stop at 3 levels even if more causes exist', () => {
const errorLevel4 = new Error('Fourth level error');
const errorLevel3 = new Error('Third level error');
const errorLevel2 = new Error('Second level error');
const errorLevel1 = new Error('First level error');
const rootError = new Error('Root error');

(errorLevel3 as any).cause = errorLevel4;
(errorLevel2 as any).cause = errorLevel3;
(errorLevel1 as any).cause = errorLevel2;
(rootError as any).cause = errorLevel1;

const crashData = InstabugUtils.getCrashDataFromError(rootError);

const thirdLevel = crashData.cause_crash?.cause_crash?.cause_crash;
expect(thirdLevel?.message).toBe('Error - Third level error');
expect(thirdLevel?.cause_crash).toBeUndefined(); // should not include 4th level
});
});

describe('reportNetworkLog', () => {
Expand Down