Skip to content

Commit

Permalink
Revert D47015785: Wrap NullPointerExceptions when thrown and throw ne…
Browse files Browse the repository at this point in the history
…w Error in dispatchViewManagerCommand for readability

Differential Revision:
D47015785

Original commit changeset: 33e0b8fbc7dc

Original Phabricator Diff: D47015785

fbshipit-source-id: 479aeb038635fbeccdea6fab252205d3d5a001b3
  • Loading branch information
javache authored and facebook-github-bot committed Jul 11, 2023
1 parent 3ff0160 commit 52698e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
16 changes: 0 additions & 16 deletions packages/react-native/Libraries/ReactNative/UIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,6 @@ const UIManager = {
commandName: number | string,
commandArgs: any[],
) {
// Sometimes, libraries directly pass in the output of `findNodeHandle` to
// this function without checking if it's null. This guards against that
// case. We throw early here in Javascript so we can get a JS stacktrace
// instead of a harder-to-debug native Java or Objective-C stacktrace.
if (typeof reactTag !== 'number') {
let stringifiedArgs = '(failed to stringify commandArgs)';
try {
stringifiedArgs = JSON.stringify(commandArgs);
} catch (err) {
// Do nothing. We have a default message
}
throw new Error(
`dispatchViewManagerCommand: found null reactTag with args ${stringifiedArgs}`,
);
}

if (isFabricReactTag(reactTag)) {
const FabricUIManager = nullthrows(getFabricUIManager());
const shadowNode =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,44 +356,37 @@ public void invoke(JSInstance jsInstance, ReadableArray parameters) {
mArgumentExtractors[i].extractArgument(jsInstance, parameters, jsArgumentsConsumed);
jsArgumentsConsumed += mArgumentExtractors[i].getJSArgumentsNeeded();
}
} catch (UnexpectedNativeTypeException | NullPointerException e) {
} catch (UnexpectedNativeTypeException e) {
throw new NativeArgumentsParseException(
e.getMessage()
+ " (constructing arguments for "
+ traceName
+ " at argument index "
+ getAffectedRange(
jsArgumentsConsumed, mArgumentExtractors[i].getJSArgumentsNeeded())
+ ") with parameters "
+ parameters.toArrayList(),
+ ")",
e);
}

try {
mMethod.invoke(mModuleWrapper.getModule(), mArguments);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(createInvokeExceptionMessage(traceName, parameters), e);
} catch (IllegalArgumentException ie) {
throw new RuntimeException("Could not invoke " + traceName, ie);
} catch (IllegalAccessException iae) {
throw new RuntimeException("Could not invoke " + traceName, iae);
} catch (InvocationTargetException ite) {
// Exceptions thrown from native module calls end up wrapped in InvocationTargetException
// which just make traces harder to read and bump out useful information
if (ite.getCause() instanceof RuntimeException) {
throw (RuntimeException) ite.getCause();
}
throw new RuntimeException(createInvokeExceptionMessage(traceName, parameters), ite);
throw new RuntimeException("Could not invoke " + traceName, ite);
}
} finally {
SystraceMessage.endSection(TRACE_TAG_REACT_JAVA_BRIDGE).flush();
}
}

/**
* Makes it easier to determine the cause of an error invoking a native method from Javascript
* code by adding the function and parameters.
*/
private static String createInvokeExceptionMessage(String traceName, ReadableArray parameters) {
return "Could not invoke " + traceName + " with parameters " + parameters.toArrayList();
}

/**
* Determines how the method is exported in JavaScript: METHOD_TYPE_ASYNC for regular methods
* METHOD_TYPE_PROMISE for methods that return a promise object to the caller. METHOD_TYPE_SYNC
Expand Down

0 comments on commit 52698e7

Please sign in to comment.