Skip to content

FormatException when enabling NativeOptions.EnableBeforeSend #3572

@jamescrosswell

Description

@jamescrosswell

Originally posted by @phunkeler in #3549

I tried enabling the EnableBeforeSend Android option but was met by the following exception that seemed to prevent other events from reaching Sentry.

C# Code

#if ANDROID
options.Native.EnableBeforeSend = true;
#endif

options.SetBeforeSend((sentryEvent, sentryHint) =>
{
    if (sentryAttachmentProvider.GetLogAttachment() is LogAttachment logAttachment)
    {
        sentryHint.Attachments.Add(logAttachment);
    }
    return sentryEvent;
});

Sentry Exception

System.FormatException: One of the identified items was in an invalid format.
  File "ThrowHelper.cs", line 594, in void ThrowHelper.ThrowFormatException()
    throw new FormatException { Source = ExceptionSourceValueToRethrowAsJsonException };
  File "JsonElement.cs", line 660, in int JsonElement.GetInt32()
    ThrowHelper.ThrowFormatException();
  File "Device.cs", line 459, in Device Device.FromJson(JsonElement json)
    var processorFrequency = json.GetPropertyOrNull("processor_frequency")?.GetInt32();
  File "SentryContexts.cs", line 148, in SentryContexts SentryContexts.FromJson(JsonElement json)
    result[name] = Device.FromJson(value);
  File "MiscExtensions.cs", line 5, in SentryContexts MiscExtensions.Pipe<JsonElement, SentryContexts>(JsonElement input, Func<JsonElement, SentryContexts> pipe)
    public static TOut Pipe<TIn, TOut>(this TIn input, Func<TIn, TOut> pipe) => pipe(input);
  File "SentryEvent.cs", line 305, in SentryEvent SentryEvent.FromJson(JsonElement json, Exception exception)
    var contexts = json.GetPropertyOrNull("contexts")?.Pipe(SentryContexts.FromJson);
  File "SentryEventExtensions.cs", line 29, in SentryEvent SentryEventExtensions.ToSentryEvent(SentryEvent sentryEvent, SentryOptions javaOptions)
    return SentryEvent.FromJson(json.RootElement, sentryEvent.Throwable);
  File "BeforeSendCallback.cs", line 26, in SentryEvent BeforeSendCallback.Execute(SentryEvent e, Hint h)
    var evnt = e.ToSentryEvent(_javaOptions);
  ?, in IntPtr IBeforeSendCallbackInvoker.n_Execute_Lio_sentry_SentryEvent_Lio_sentry_Hint_(IntPtr jnienv, IntPtr native__this, IntPtr native_p0, IntPtr native_p1)
  File "/Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs", line 231, col 5, in IntPtr JNINativeWrapper.Wrap_JniMarshal_PPLL_L(_JniMarshal_PPLL_L callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions