1515using Hearthstone_Deck_Tracker . Utility . Extensions ;
1616using Hearthstone_Deck_Tracker . Utility . Logging ;
1717using Hearthstone_Deck_Tracker . Utility . RemoteData ;
18+ using Newtonsoft . Json ;
19+ using Newtonsoft . Json . Linq ;
1820using SharpRaven ;
1921using SharpRaven . Data ;
2022
@@ -198,7 +200,7 @@ private static void SendQueuedBobsBuddyEvents(string? shortId, string path, Func
198200 var e = BobsBuddyEvents . Dequeue ( ) ;
199201 ( ( BobsBuddyData ) e . Extra ) . ShortId = shortId ;
200202
201- var eventId = Client . Capture ( recode ( e ) ) ;
203+ var eventId = Client . Capture ( WithSerializableExtra ( recode ( e ) ) ) ;
202204 if ( eventId != null )
203205 sent ++ ;
204206 else
@@ -224,6 +226,20 @@ private static SentryEvent RecodeIfBothSidesEmpty(SentryEvent e)
224226 private static SentryEvent RecodeAsStateCompleteFalse ( SentryEvent e ) =>
225227 Recode ( e , $ "BobsBuddy { BobsBuddyUtils . VersionString } : Incorrect Terminal Case: StateCompleteFalse") ;
226228
229+ private static SentryEvent WithSerializableExtra ( SentryEvent e )
230+ {
231+ if ( e . Extra == null )
232+ return e ;
233+ // BobsBuddy entities contain reference cycles (Enchantment.AttachedTo), which make SharpRaven's serialization throw
234+ var serializer = JsonSerializer . Create ( new JsonSerializerSettings
235+ {
236+ ReferenceLoopHandling = ReferenceLoopHandling . Ignore ,
237+ Error = ( _ , args ) => args . ErrorContext . Handled = true ,
238+ } ) ;
239+ e . Extra = JObject . FromObject ( e . Extra , serializer ) ;
240+ return e ;
241+ }
242+
227243 private static SentryEvent Recode ( SentryEvent e , string message ) =>
228244 new SentryEvent ( new SentryMessage ( message ) )
229245 {
0 commit comments