mirror of
https://github.com/status-im/instabug-reactnative.git
synced 2025-03-03 14:40:54 +00:00
Merge pull request #19 from Instabug/feature/introduse-crash-reporting-for-js-crashes
Feature/introduse crash reporting for js crashes
This commit is contained in:
commit
fba29cb055
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ android/.DS_Store
|
|||||||
ios/.DS_Store
|
ios/.DS_Store
|
||||||
|
|
||||||
build/
|
build/
|
||||||
|
/android/src/main/java/com/instabug/reactlibrary/wrappedAPIs
|
||||||
|
@ -6,6 +6,9 @@ import android.net.Uri;
|
|||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
import com.facebook.react.bridge.ReactMethod;
|
import com.facebook.react.bridge.ReactMethod;
|
||||||
|
import com.facebook.react.bridge.ReadableArray;
|
||||||
|
import com.facebook.react.bridge.ReadableMap;
|
||||||
|
|
||||||
import com.instabug.library.Instabug;
|
import com.instabug.library.Instabug;
|
||||||
import com.instabug.library.internal.module.InstabugLocale;
|
import com.instabug.library.internal.module.InstabugLocale;
|
||||||
import com.instabug.library.invocation.InstabugInvocationEvent;
|
import com.instabug.library.invocation.InstabugInvocationEvent;
|
||||||
@ -430,6 +433,36 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report a caught exception to Instabug dashboard
|
||||||
|
*
|
||||||
|
* @param throwable the exception to be reported
|
||||||
|
*/
|
||||||
|
@ReactMethod
|
||||||
|
public void reportJsException(ReadableArray stack, String message, String errorIdentifier) {
|
||||||
|
try {
|
||||||
|
int size = stack != null ? stack.size() : 0;
|
||||||
|
StackTraceElement[] stackTraceElements = new StackTraceElement[size];
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
ReadableMap frame = stack.getMap(i);
|
||||||
|
String methodName = frame.getString("methodName");
|
||||||
|
String fileName = frame.getString("file");
|
||||||
|
int lineNumber = frame.getInt("lineNumber");
|
||||||
|
|
||||||
|
stackTraceElements[i] = new StackTraceElement(fileName, methodName, fileName, lineNumber);
|
||||||
|
}
|
||||||
|
Throwable throwable = new Throwable(message);
|
||||||
|
throwable.setStackTrace(stackTraceElements);
|
||||||
|
if (errorIdentifier != null)
|
||||||
|
mInstabug.reportException(throwable);
|
||||||
|
else
|
||||||
|
mInstabug.reportException(throwable, errorIdentifier);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Locale getLocaleByKey(String instabugLocale) {
|
private Locale getLocaleByKey(String instabugLocale) {
|
||||||
String localeInLowerCase = instabugLocale.toLowerCase();
|
String localeInLowerCase = instabugLocale.toLowerCase();
|
||||||
switch (localeInLowerCase) {
|
switch (localeInLowerCase) {
|
||||||
|
14
index.js
14
index.js
@ -5,8 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {NativeModules, NativeAppEventEmitter, Platform} from 'react-native';
|
import {NativeModules, NativeAppEventEmitter, Platform} from 'react-native';
|
||||||
|
|
||||||
let {Instabug} = NativeModules;
|
let {Instabug} = NativeModules;
|
||||||
|
import instabugParser from './utils/instabugParser.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instabug
|
* Instabug
|
||||||
@ -464,6 +464,18 @@ module.exports = {
|
|||||||
Instabug.isInstabugNotification(dict, isInstabugNotificationCallback);
|
Instabug.isInstabugNotification(dict, isInstabugNotificationCallback);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
reportJsException: function (error, errorIdentifier) {
|
||||||
|
if (!error || !error instanceof Error)
|
||||||
|
throw new Error("You should pass an error object");
|
||||||
|
|
||||||
|
let jsStackTrace = instabugParser(error);
|
||||||
|
if (!errorIdentifier)
|
||||||
|
Instabug.reportJsException(jsStackTrace, error.message, null);
|
||||||
|
else if (errorIdentifier) {
|
||||||
|
Instabug.reportJsException(jsStackTrace, error.message, errorIdentifier);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The event used to invoke the feedback form
|
* The event used to invoke the feedback form
|
||||||
* @readonly
|
* @readonly
|
||||||
|
@ -28,5 +28,8 @@
|
|||||||
"android": {
|
"android": {
|
||||||
"packageInstance": "new RNInstabugReactnativePackage(\"YOUR_ANDROID_APPLICATION_TOKEN\",MainApplication.this,\"button\")"
|
"packageInstance": "new RNInstabugReactnativePackage(\"YOUR_ANDROID_APPLICATION_TOKEN\",MainApplication.this,\"button\")"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"stacktrace-parser": "0.1.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
utils/instabugParser.js
Normal file
13
utils/instabugParser.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var stacktraceParser = require('stacktrace-parser');
|
||||||
|
|
||||||
|
function parseErrorStack(error) {
|
||||||
|
if (!error || !error.stack) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return Array.isArray(error.stack) ? error.stack :
|
||||||
|
stacktraceParser.parse(error.stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = parseErrorStack;
|
Loading…
x
Reference in New Issue
Block a user