Skip to content

Commit fc7a419

Browse files
committed
fix: possible json deserializer exception
Log if DiscordJson fails
1 parent 209a7ca commit fc7a419

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

DisCatSharp/Net/Serialization/DiscordJson.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,16 @@ private static void DiscordJsonErrorHandler(object? sender, ErrorEventArgs e, Ba
107107
var sentryMessage = "DiscordJson error on deserialization (" + (sender?.GetType().Name ?? "x") + ")\n\n" +
108108
"Path: " + e.ErrorContext.Path + "\n" +
109109
"Original Object" + e.ErrorContext.OriginalObject + "\n" +
110-
"Current Object" + e.CurrentObject;
110+
"Current Object" + e.CurrentObject + "\n\n" +
111+
"JRE Message:" + jre.Message + "\n" +
112+
"JRE Line Number: " + jre.LineNumber + "\n" +
113+
"JRE Line Position" + jre.LinePosition + "\n" +
114+
"JRE Path" + jre.Path;
111115
SentryEvent sentryEvent = new(new DiscordJsonException(jre))
112116
{
113117
Level = SentryLevel.Error,
114118
Logger = nameof(DiscordJson),
115-
Message = sentryMessage
119+
Message = Utilities.StripIds(sentryMessage, discord.Configuration.EnableDiscordIdScrubber)
116120
};
117121
sentryEvent.SetFingerprint(BaseDiscordClient.GenerateSentryFingerPrint(sentryEvent));
118122
if (discord.Configuration.AttachUserInfo && discord.CurrentUser is not null)
@@ -128,6 +132,8 @@ private static void DiscordJsonErrorHandler(object? sender, ErrorEventArgs e, Ba
128132
};
129133
var sid = discord.Sentry.CaptureEvent(sentryEvent);
130134
_ = Task.Run(discord.Sentry.FlushAsync);
135+
if (discord.Configuration.EnableLibraryDeveloperMode)
136+
discord.Logger.LogInformation("DiscordJson exception reported to sentry with id {sid}", sid.ToString());
131137
}
132138

133139
/// <summary>
@@ -202,7 +208,7 @@ private static T DeserializeObjectInternal<T>(string? json, BaseDiscordClient? d
202208
var sid = discord.Sentry.CaptureEvent(sentryEvent);
203209
_ = Task.Run(discord.Sentry.FlushAsync);
204210
if (discord.Configuration.EnableLibraryDeveloperMode)
205-
discord.Logger.LogInformation("Reported to sentry with id {sid}", sid.ToString());
211+
discord.Logger.LogInformation("Missing fields reported to sentry with id {sid}", sid.ToString());
206212

207213
return obj;
208214
}
@@ -280,7 +286,7 @@ private static T DeserializeIEnumerableObjectInternal<T>(string? json, BaseDisco
280286
var sid = discord.Sentry.CaptureEvent(sentryEvent);
281287
_ = Task.Run(discord.Sentry.FlushAsync);
282288
if (discord.Configuration.EnableLibraryDeveloperMode)
283-
discord.Logger.LogInformation("Reported to sentry with id {sid}", sid.ToString());
289+
discord.Logger.LogInformation("Missing fields reported to sentry with id {sid}", sid.ToString());
284290

285291
return obj;
286292
}

0 commit comments

Comments
 (0)