Skip to content

Commit cc8e640

Browse files
authored
Crash handler error issue fixed (#61)
* Crash handler error stack parsing issue fixed for React-Native version >= 0.64 * Changlelog updated * Typo fix in Changelog
1 parent c740500 commit cc8e640

File tree

7 files changed

+56
-28
lines changed

7 files changed

+56
-28
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 20.11.10
2+
* Error/crash stack parsing issue fixed for React-Native version >= 0.64
3+
* Underlying android SDK is 20.11.10
4+
* Underlying iOS SDK version is 20.11.1
5+
16
## 20.11.9
27
* Automatic crash reporting issue fixed.
38
* Android background session logging issue fixed.

Countly.js

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @Countly
55
*/
66

7-
import {
7+
import {
88
Platform,
99
NativeModules,
1010
NativeEventEmitter
@@ -308,31 +308,34 @@ Countly.enableCrashReporting = async function(){
308308
}
309309
var previousHandler = ErrorUtils.getGlobalHandler();
310310
ErrorUtils.setGlobalHandler(function (error, isFatal) {
311-
var jsStackTrace = parseErrorStackLib(error);
312-
var fname = jsStackTrace[0].file;
313-
if (fname.startsWith("http")) {
314-
var chunks = fname.split("/");
315-
fname = chunks[chunks.length-1].split("?")[0];
311+
let jsStackTrace = Countly.getStackTrace(error);
312+
let errorTitle;
313+
let stackArr;
314+
if(jsStackTrace == null) {
315+
errorTitle = error.name;
316+
stackArr = error.stack;
316317
}
317-
var errorTitle = `${error.name} (${jsStackTrace[0].methodName}@${fname})`;
318-
const regExp = "(.*)(@?)http(s?).*/(.*)\\?(.*):(.*):(.*)";
319-
const stackArr = error.stack.split("\n").map(row => {
320-
row = row.trim();
321-
if (!row.includes("http")) return row;
322-
else {
323-
const matches = row.match(regExp);
324-
return matches && matches.length == 8 ? `${matches[1]}${matches[2]}${matches[4]}(${matches[6]}:${matches[7]})` : row;
318+
else {
319+
var fname = jsStackTrace[0].file;
320+
if (fname.startsWith("http")) {
321+
var chunks = fname.split("/");
322+
fname = chunks[chunks.length-1].split("?")[0];
325323
}
326-
})
327-
const stack = stackArr.join("\n");
328-
if (Platform.OS.match("android")) {
329-
CountlyReactNative.logJSException(errorTitle, error.message.trim(), stack);
330-
}
331-
else if (Platform.OS.match("ios")) {
332-
const errMessage = `[React] ${errorTitle}: ${error.message}`;
333-
const errStack = error.message + "\n" + stack;
334-
CountlyReactNative.logJSException(errorTitle, errMessage, errStack);
324+
errorTitle = `${error.name} (${jsStackTrace[0].methodName}@${fname})`;
325+
const regExp = "(.*)(@?)http(s?).*/(.*)\\?(.*):(.*):(.*)";
326+
stackArr = error.stack.split("\n").map(row => {
327+
row = row.trim();
328+
if (!row.includes("http")) return row;
329+
else {
330+
const matches = row.match(regExp);
331+
return matches && matches.length == 8 ? `${matches[1]}${matches[2]}${matches[4]}(${matches[6]}:${matches[7]})` : row;
332+
}
333+
})
334+
stackArr = stackArr.join("\n");
335335
}
336+
337+
CountlyReactNative.logJSException(errorTitle, error.message.trim(), stackArr);
338+
336339
if (previousHandler) {
337340
previousHandler(error, isFatal);
338341
}
@@ -341,6 +344,26 @@ Countly.enableCrashReporting = async function(){
341344
Countly.isCrashReportingEnabled = true;
342345
}
343346

347+
Countly.getStackTrace = (e) => {
348+
let jsStackTrace = null;
349+
try {
350+
if (Platform.hasOwnProperty("constants")) {
351+
// RN version >= 0.63
352+
if (Platform.constants.reactNativeVersion.minor >= 64)
353+
// RN version >= 0.64
354+
jsStackTrace = parseErrorStackLib(e.stack);
355+
// RN version == 0.63
356+
else jsStackTrace = parseErrorStackLib(e);
357+
}
358+
// RN version < 0.63
359+
else jsStackTrace = parseErrorStackLib(e);
360+
}
361+
catch (e) {
362+
// console.log(e.message);
363+
}
364+
return jsStackTrace;
365+
};
366+
344367
Countly.addCrashLog = function(crashLog){
345368
CountlyReactNative.addCrashLog([crashLog]);
346369
}

CountlyReactNative.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'CountlyReactNative'
3-
s.version = '20.11.9'
3+
s.version = '20.11.10'
44
s.license = {
55
:type => 'COMMUNITY',
66
:text => <<-LICENSE

android/src/main/java/ly/count/android/sdk/react/CountlyReactNative.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public String toString(){
7474
public class CountlyReactNative extends ReactContextBaseJavaModule implements LifecycleEventListener {
7575

7676
public static final String TAG = "CountlyRNPlugin";
77-
private String COUNTLY_RN_SDK_VERSION_STRING = "20.11.9";
77+
private String COUNTLY_RN_SDK_VERSION_STRING = "20.11.10";
7878
private String COUNTLY_RN_SDK_NAME = "js-rnb-android";
7979

8080
private static CountlyConfig config = new CountlyConfig();

example/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rm App.js
1111
curl https://raw.githubusercontent.com/Countly/countly-sdk-react-native-bridge/master/example/App.js --output App.js
1212
curl https://raw.githubusercontent.com/Countly/countly-sdk-react-native-bridge/master/example/Example.js --output Example.js
1313

14-
14+
yarn add [email protected].10
1515

1616
cd ./ios
1717
pod install

ios/src/CountlyReactNative.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ @interface CountlyFeedbackWidget ()
2121
+ (CountlyFeedbackWidget *)createWithDictionary:(NSDictionary *)dictionary;
2222
@end
2323

24-
NSString* const kCountlyReactNativeSDKVersion = @"20.11.9";
24+
NSString* const kCountlyReactNativeSDKVersion = @"20.11.10";
2525
NSString* const kCountlyReactNativeSDKName = @"js-rnb-ios";
2626

2727
CountlyConfig* config = nil;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "countly-sdk-react-native-bridge",
3-
"version": "20.11.9",
3+
"version": "20.11.10",
44
"author": "Countly <[email protected]> (https://count.ly/)",
55
"bugs": {
66
"url": "https://github.com/Countly/countly-sdk-react-native-bridge/issues"

0 commit comments

Comments
 (0)