Skip to content
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

Errors on Android don't have a message: Unknown std::runtime_error error #382

Open
2 of 5 tasks
mrousavy opened this issue Dec 2, 2024 · 13 comments
Open
2 of 5 tasks
Labels
nitro-core Issue is related to the Nitro Modules core runtime/C++ codebase

Comments

@mrousavy
Copy link
Owner

mrousavy commented Dec 2, 2024

What's happening?

On Android, errors / exceptions don't have a proper message, and always resort to Unknown T error (e.g. Unknown std::runtime_error error) instead of using it's message (what()).

The same goes for Promise<T>.

I can't really figure out why this is happening - my best guess is that there is some ABI issue with the libc++ standard used by Android NDK, and since errors in Nitro are implemented using std::exception_ptr, the methods current_exception()/rethrow_exception(..) are broken in Android.
I created an issue in the react-native repo: facebook/react-native#48027

Reproduceable Code

class MyHybrid: public MyHybridSpec {
  // ...
public:
  void someFunc() override {
    throw std::runtime_error("my message!");
  }
};

Relevant log output

iOS ✅:

MyHybrid.someFunc(): my message!

Android ❌:

MyHybrid.someFunc() threw an unknown std::runtime_error error.

Device

Huawei P10

Nitro Modules Version

0.18.1

Nitrogen Version

0.18.1

Can you reproduce this issue in the Nitro Example app here?

Yes, I can reproduce the same issue in the Example app here

Additional information

@mrousavy mrousavy added the nitro-core Issue is related to the Nitro Modules core runtime/C++ codebase label Dec 2, 2024
@mrousavy
Copy link
Owner Author

mrousavy commented Dec 2, 2024

cc @Szymon20000

@mrousavy
Copy link
Owner Author

mrousavy commented Dec 3, 2024

Actually this is a react-native bug, not a Nitro bug. It can be reproduced in a blank new react-native 0.76 or 0.77 app. facebook/react-native#48027

@jobpaardekooper
Copy link

Since this is a RN bug, do you know any issue number/link on their repo that tracks this?

@mrousavy
Copy link
Owner Author

yea see my comment directly above yours

@jobpaardekooper
Copy link

I don't know how I missed that... sorry. Thanks for the reply.

@iwater
Copy link

iwater commented Jan 1, 2025

this also show on ios platform with [email protected]

Error: `NitroModulesProxy.createHybridObject(...)` threw an unknown std::runtime_error error.

@mrousavy
Copy link
Owner Author

mrousavy commented Jan 1, 2025

@iwater i cannot reproduce this on iOS - which Nitro version? can you reproduce this in the NitroExample app here?

@iwater
Copy link

iwater commented Jan 1, 2025

0.20.1,I just use template folder code as library template and add Math code from doc, then got that error message , I just put that code on https://github.com/iwater/react-native-nitro-crypto2

@iwater
Copy link

iwater commented Jan 2, 2025

sorry, I just create a new project, it can show detail error message now.

@Nlcke
Copy link

Nlcke commented Jan 13, 2025

Is unknown facebook::jni::JniException error related to this issue? For example:

(NOBRIDGE) ERROR  [Error: `Math.throwError(...)` threw an unknown facebook::jni::JniException error.]

The Kotlin class is:

package com.margelo.nitro.math

class HybridMath : HybridMathSpec() {
    override val memorySize = 0L

    override fun throwError() {
        throw Error("THIS IS ERROR!")
    }
}

@mrousavy
Copy link
Owner Author

mrousavy commented Jan 13, 2025

Yup, same story here.

Unfortunately caused by the new SoLoader merging changes introduced in RN 0.76. Not sure if this only affects Nitro Modules or also (C++) TurboModules as well.

@Nlcke If you can try what @cortinico suggested in this comment, that would be a huge help.

@cortinico
Copy link

Unfortunately caused by the new SoLoader merging changes introduced in RN 0.76

Has this been confirmed as being the root cause?

@mrousavy
Copy link
Owner Author

Not 100%, no. Should've phrased this differently.
But I'm pretty sure we can figure that out if we try your suggestion in your comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nitro-core Issue is related to the Nitro Modules core runtime/C++ codebase
Projects
None yet
Development

No branches or pull requests

5 participants