Skip to content

Fetch operations not working inside nativehandler #168

@W1nstar

Description

@W1nstar

I get the native UI when the rn-test-exception-handler is called, and the JS code executes till the fetch, where it stops without error of any kind.

const nativeErrorHandler = async (error, isFatal) => {
  // Log error to Sentry
  console.log("1 coming from JAVA")
  try {
    console.log("2 going for a fetch fetch")
    await fetch('https://jsonplaceholder.typicode.com/users')
    console.log("3 fetch done")
  } catch (e) {
    console.log("4 something failed", e)
  }
  

};

setNativeExceptionHandler(nativeErrorHandler, false);

And this is how the logcat reads:

    --------- beginning of crash
2022-08-03 12:21:15.436 7832-7863/com.mobilea E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
    Process: com.mobilea, PID: 7832
    java.lang.RuntimeException: Could not invoke RnTestExceptionHandler.raiseTestNativeError
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:382)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:150)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26)
        at android.os.Looper.loop(Looper.java:193)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:371)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:150) 
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26) 
        at android.os.Looper.loop(Looper.java:193) 
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225) 
        at java.lang.Thread.run(Thread.java:764) 
     Caused by: java.lang.Exception: TEST EXCEPTION ON ANDROID
        at com.masteratul.rn.testexception.RnTestExceptionHandlerModule.raiseTestNativeError(RnTestExceptionHandlerModule.java:27)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:371) 
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:150) 
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26) 
        at android.os.Looper.loop(Looper.java:193) 
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225) 
        at java.lang.Thread.run(Thread.java:764) 
2022-08-03 12:21:15.406 7832-7862/com.mobilea I/chatty: uid=10091(com.mobilea) mqt_js identical 2 lines
2022-08-03 12:21:15.406 7832-7862/com.mobilea I/ReactNativeJS: 'child.type.name', [Function: b]
2022-08-03 12:21:15.436 7832-7863/com.mobilea D/debug en java prueba 2: prueba
2022-08-03 12:21:15.437 7832-7863/com.mobilea D/debug en java prueba 4: prueba
    
    --------- beginning of system
2022-08-03 12:21:15.450 7832-7862/com.mobilea I/ReactNativeJS: 1 coming from JAVA
2022-08-03 12:21:15.450 7832-7862/com.mobilea I/ReactNativeJS: 2 going for a fetch fetch
2022-08-03 12:21:15.450 7832-7832/com.mobilea W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@4497442
2022-08-03 12:21:15.524 7832-7860/com.mobilea D/EGL_emulation: eglMakeCurrent: 0xe5e6b320: ver 2 0 (tinfo 0xd56cc2e0)
2022-08-03 12:21:16.138 7832-7832/com.mobilea D/ReactNative: ReactInstanceManager.detachViewFromInstance()

Android Studio's network inspector shows no internet usage at all.

Any idea of what's going on? Workaround? Tried axios, same thing happens. Tried referencing methods defined outside the handler function and they work. It looks like any http request will fail, but without error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions