Sentry-react-native: Null property values on the object passed to Sentry.setExtraContext cause an error for iOS

Created on 16 Jun 2018  ·  3Comments  ·  Source: getsentry/sentry-react-native

OS:

  • [ ] Windows
  • [X] MacOS
  • [ ] Linux

_Platform:_

  • [X] iOS
  • [ ] Android
v6.11.1
3.10.10
[Redacted]@0.0.1 [Redacted]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Config:

Sentry.config('https://[email protected]/...', {
    logLevel: SentryLog.Error
}).install()

I have the following issue:

I am having a similar issue as this issue except it occurs when making a Sentry.setExtraContext call. This error only occurs on iOS.

I was able to workaround the issue to an extent using the following code to change what certain properties (listed in the steps to reproduce below) were set to on the object passed to Sentry.setExtraContext:

function getSentrySetExtraContextObjectForIOS(setExtraContextObject: any): any {
    const setExtraContextObjectClone = {...setExtraContextObject};

    for (const setExtraContextObjectPropertyName in setExtraContextObject) {
        setExtraContextObjectClone[setExtraContextObjectPropertyName] = getSentrySetExtraContextObjectPropertyValueForIOS(setExtraContextObject[setExtraContextObjectPropertyName]);
    }

    return setExtraContextObjectClone;
}

function getSentrySetExtraContextObjectPropertyValueForIOS(setExtraContextObjectPropertyValue: any): any {
    if (setExtraContextObjectPropertyValue === null) {
        return "sentrySetExtraContextNullValueIOSWorkaround";
    }
    else if (_.isPlainObject(setExtraContextObjectPropertyValue)) {
        return getSentrySetExtraContextObjectForIOS(setExtraContextObjectPropertyValue);
    }
    else if (Array.isArray(setExtraContextObjectPropertyValue)) {
        return setExtraContextObjectPropertyValue.map((value, index, array) => {
            return getSentrySetExtraContextObjectPropertyValueForIOS(value);
        });
    }
    else {
        return setExtraContextObjectPropertyValue;
    }
}

This code doesn't cover arrays that only have certain indexes set on them so I just deleted those properties from the cloned object.

After all that, we decided that we would rather be sure we will get an error in Sentry so we are not using this workaround and omitting the object causing the error from the object passed to Sentry.setExtraContext with the hope that this GitHub issue will be resolved.

Steps to reproduce:

  • Pass Sentry.setExtraContext an object with at least one property (it can be a nested object property) that has one of the following values:

    • null
    • An array with null values in it.
    • An array of objects with at least one property with a null value.
    • An array with only some indexes set.
  • Run on iOS

  • Execute code that makes the Sentry.setExtraContext call get hit.

Actual result:

  • The following error occurs on line 292 of SentryClient.m:
[[NSUserDefaults standardUserDefaults] setObject:extra forKey:@"sentry.io.extra"];
2018-06-15 16:42018-06-15 16:47:23.074 [fatal][tid:main] Exception 'Attempt to insert non-property list object {
    RedactedPropertyName = "<null>";
} for key sentry.io.extra' was thrown while invoking setExtra on target RNSentry with params (
        {
        RedactedPropertyName = "<null>";
    }
)
callstack: (
    0   CoreFoundation                      0x0000000185fe717c <redacted> + 148
    1   libobjc.A.dylib                     0x0000000185230528 objc_exception_throw + 56
    2   CoreFoundation                      0x0000000185fe70ac <redacted> + 0
    3   CoreFoundation                      0x000000018601f648 <redacted> + 252
    4   CoreFoundation                      0x0000000185f530e0 <redacted> + 632
    5   CoreFoundation                      0x0000000185f51648 <redacted> + 440
    6   CoreFoundation                      0x000000018601f9d4 <redacted> + 220
    7   CoreFoundation                      0x0000000185f82274 <redacted> + 604
    8   CoreFoundation                      0x000000018601f9d4 <redacted> + 220
    9   CoreFoundation                      0x000000018601fc58 <redacted> + 64
    10  CoreFoundation                      0x0000000185f852f0 <redacted> + 268
    11  CoreFoundation                      0x0000000185f84b0c <redacted> + 356
    12  CoreFoundation                      0x0000000185f851d8 <redacted> + 108
    13  CoreFoundation                      0x0000000186029a4c <redacted> + 92
    14  CoreFoundation                      0x000000018602d0cc _CFPreferencesSetAppValueWithContainer + 128
    15  Foundation                          0x00000001868efe30 <redacted> + 68
    16  mobile                              0x0000000104e207bc -[SentryClient setExtra:] + 140
    17  mobile                              0x0000000104d9add4 -[RNSentry setExtra:] + 116
    18  CoreFoundation                      0x0000000185feead0 <redacted> + 144
    19  CoreFoundation                      0x0000000185ecd36c <redacted> + 292
    20  CoreFoundation                      0x0000000185ed1e1c <redacted> + 60
    21  mobile                              0x0000000104bb1464 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2064
    22  mobile                              0x0000000104c44890 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 664
    23  mobile                              0x0000000104c44420 _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 132
    24  mobile                              0x0000000104c44390 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 28
    25  libdispatch.dylib                   0x00000001057812cc _dispatch_call_block_and_release + 24
    26  libdispatch.dylib                   0x000000010578128c _dispatch_client_callout + 16
    27  libdispatch.dylib                   0x0000000105785ea0 _dispatch_main_queue_callback_4CF + 1196
    28  CoreFoundation                      0x0000000185f8f344 <redacted> + 12
    29  CoreFoundation                      0x0000000185f8cf20 <redacted> + 2012
    30  CoreFoundation                      0x0000000185eacc58 CFRunLoopRunSpecific + 436
    31  GraphicsServices                    0x0000000187d58f84 GSEventRunModal + 100
    32  UIKit                               0x000000018f6055c4 UIApplicationMain + 236
    33  mobile                              0x0000000104b1a274 main + 124
    34  libdyld.dylib                       0x00000001859cc56c <redacted> + 4
)

Expected result:

  • No error and the extra context properly displayed in Sentry.
🦔react-native-sentry

Most helpful comment

any update on this?

All 3 comments

any update on this?

same error

I am closing all old issues, please if this is still a problem feel free to revive it.
Also, consider moving to our new SDK @sentry/react-native if it still happens there please open a new issue.

Was this page helpful?
0 / 5 - 0 ratings