Skip to content

Handle missing arguments in sendNativeNonFatal to prevent NativeArgumentsParseException #1421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,39 @@ public void sendHandledJSCrash(final String exceptionObject, @Nullable final Rea
try {
final JSONObject jsonObject = new JSONObject(exceptionObject);
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
public void run() {
@ReactMethod
public void sendNativeNonFatal(@Nullable ReadableMap params) {
if (params == null) {
// Optionally log or handle the missing argument case gracefully
return;
}
try {
Method method = getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException", JSONObject.class, boolean.class,
Map.class, JSONObject.class, IBGNonFatalException.Level.class);
JSONObject jsonObject = new JSONObject(params.hasKey("jsonObject") ? params.getString("jsonObject") : "{}");
IBGNonFatalException.Level nonFatalExceptionLevel = IBGNonFatalException.Level.ERROR;
if (params.hasKey("level")) {
String level = params.getString("level");
if (ArgsRegistry.nonFatalExceptionLevel != null) {
nonFatalExceptionLevel = ArgsRegistry.nonFatalExceptionLevel.getOrDefault(level, IBGNonFatalException.Level.ERROR);
}
}
Map<String, Object> userAttributesMap = null;
if (params.hasKey("userAttributes")) {
ReadableMap userAttributes = params.getMap("userAttributes");
userAttributesMap = userAttributes != null ? userAttributes.toHashMap() : null;
}
JSONObject fingerprintObj = null;
if (params.hasKey("fingerprint")) {
String fingerprint = params.getString("fingerprint");
if (fingerprint != null) {
fingerprintObj = CrashReporting.getFingerprintObject(fingerprint);
}
}
Method method = getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException", JSONObject.class, boolean.class, Map.class, JSONObject.class, IBGNonFatalException.Level.class);
if (method != null) {
IBGNonFatalException.Level nonFatalExceptionLevel = ArgsRegistry.nonFatalExceptionLevel.getOrDefault(level, IBGNonFatalException.Level.ERROR);
Map<String, Object> userAttributesMap = userAttributes == null ? null : userAttributes.toHashMap();
JSONObject fingerprintObj = fingerprint == null ? null : CrashReporting.getFingerprintObject(fingerprint);

method.invoke(null, jsonObject, true, userAttributesMap, fingerprintObj, nonFatalExceptionLevel);

RNInstabugReactnativeModule.clearCurrentReport();
}
} catch (ClassNotFoundException | IllegalAccessException |
InvocationTargetException e) {
} catch (Exception e) {
e.printStackTrace();
}
}
Expand Down