adobe / aepsdk_flutter

Apache License 2.0
10 stars 12 forks source link

Null check operator used on a null value - iOS #127

Open MaikuB opened 1 week ago

MaikuB commented 1 week ago

Prerequisites

Bug summary

Working on an app where exceptions are occasionally reported when calling the this API. What's logged is that a null check was used on a null value on the following lines

https://github.com/adobe/aepsdk_flutter/blob/e385131d4f26ee4774fd19fd64ccd35c39fc1053/plugins/flutter_aepcore/lib/flutter_aepidentity.dart#L76 https://github.com/adobe/aepsdk_flutter/blob/e385131d4f26ee4774fd19fd64ccd35c39fc1053/plugins/flutter_aepcore/lib/flutter_aepidentity.dart#L43

This means the plugin itself expected a non-nullable values. Don't have steps to reproduce as tracing through the source code of the plugin shows that it does not check the error object on the iOS side and assumes calling the native iOS SDK works https://github.com/adobe/aepsdk_flutter/blob/e385131d4f26ee4774fd19fd64ccd35c39fc1053/plugins/flutter_aepcore/ios/Classes/FlutterAEPIdentityPlugin.m#L93. This effectively means the plugin is swallowing any errors being reported on the native and makes it difficult to know what went wrong. The following is an example of dealing with a NSError object on the iOS side can be done https://github.com/flutter/packages/blob/aa741d164ccd24aaaaee5fe4b4c1dcf9df931799/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraPlugin.m#L19. This would allow the plugin to throw a PlatformException on Dart/Flutter side that apps can catch and get more detailed information on what went wrong. Note the docs for AEP also refer to catching a PlatformException (e.g. here), however it's not possible on iOS with how the plugin hasn't properly handled errors. This is in turn means it's not possible to see the AEPError code

Environment

[✓] Flutter (Channel stable, 3.24.2, on macOS 15.0.1 24A348 darwin-arm64, locale en-AU) [!] Android toolchain - develop for Android devices (Android SDK version 35.0.0) ✗ cmdline-tools component is missing Run path/to/sdkmanager --install "cmdline-tools;latest" See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run flutter doctor --android-licenses to accept the SDK licenses. See https://flutter.dev/to/macos-android-setup for more details. [✓] Xcode - develop for iOS and macOS (Xcode 16.0) [✓] Chrome - develop for the web [✓] Android Studio (version 2024.1) [✓] VS Code (version 1.93.1) [✓] Connected device (3 available) ! Error: Browsing on the local area network for Michael’s iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27) [✓] Network resources

Steps to reproduce

N/A

Current behavior

Null check operator used on a null value error being thrown

Expected behavior

SDK throws a PlatformException containing details of the from the native side

Anything else?

No response

cacheung commented 2 days ago

@MaikuB Thanks for reporting the issue, we'll review the issue.