adaptyteam / AdaptySDK-React-Native

React Native SDK for growing in-app subscriptions
https://docs.adapty.io/docs/quickstart
MIT License
122 stars 12 forks source link

"Failed to deserialize a native error message" on SDK initialization #76

Closed canpoyrazoglu closed 1 year ago

canpoyrazoglu commented 1 year ago

Description

I'm trying to initialize the SDK:

   adapty.activate(env.adaptySdkKey, { customerUserId }).then(async () => {
          ...
        });

My env.adaptySdkKey and customerUserId are set and valid. However when I'm initing I get a console warning:

Failed to deserialize a native error message

Digging down further into React Native bridge and putting a breakpoint there reveals the following details with the provided error data object:

{
  "code":"adapty_native_error",
  "message":"Argument 'id' was not passed to a native module.",
  "domain":"RCTErrorDomain",
  [...]
}

What am I doing wrong? (Tried iOS-only. I currently can't test Android so I don't know it happens on Android too or not)

Version

2.4.2

What platforms are you seeing the problem on?

iOS

System info

System:
    OS: macOS 13.3.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 178.22 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.18.0 - ~/.nvm/versions/node/v16.18.0/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v16.18.0/bin/npm
    Watchman: 2023.05.15.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.12.0 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK:
      Android NDK: 17.2.4988734
  IDEs:
    Android Studio: 2022.2 AI-222.4459.24.2221.9862592
    Xcode: 14.3/14E222b - /usr/bin/xcodebuild
  Languages:
    Java: 18.0.1.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.6 => 0.71.6 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
divanc commented 1 year ago

Oh, hi there! I've just answered you in StackOverflow, glad you're here. Let me paste here the reply:

From the provided code I can see only one possible buggy place: customerUserId should be a nullable string (string | undefined | null) and native layer may throw an error if you've passed a number for example.

Although in this customerUserId case the error should be: _"Argument 'userid' was not passed to a native module." The only place, where I can expect 'id' is in adapty.getPaywall(paywallId) method.

Make sure, that:

  1. getPaywall is not being called somewhere without the first required argument
  2. The first paywallId argument is of string type

Meanwhile, I'll make sure that errors deserialize without any pain

divanc commented 1 year ago

@canpoyrazoglu, mentioning in case you are not notified by default ☝️

canpoyrazoglu commented 1 year ago

Hi,

After further investigation I've found that I was passing an object whereas I should be passing ID string. I had some refactoring around Adapty and paywalls but forgot to change that one line of code (which was previously working with object instead of ID).

Now it works. Completely my bad!