Skip to content

Commit b87ec6e

Browse files
authored
option to dump gw payloads on errors (#2999)
* option to dump gw payloads on errors * w a r n i n g
1 parent c53aac3 commit b87ec6e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Discord.Net.WebSocket/DiscordSocketClient.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public partial class DiscordSocketClient : BaseSocketClient, IDiscordClient
8383
internal bool AlwaysResolveStickers { get; private set; }
8484
internal bool LogGatewayIntentWarnings { get; private set; }
8585
internal bool SuppressUnknownDispatchWarnings { get; private set; }
86+
internal bool IncludeRawPayloadOnGatewayErrors { get; private set; }
8687
internal int AuditLogCacheSize { get; private set; }
8788

8889
internal new DiscordSocketApiClient ApiClient => base.ApiClient;
@@ -158,6 +159,7 @@ private DiscordSocketClient(DiscordSocketConfig config, API.DiscordSocketApiClie
158159
AlwaysResolveStickers = config.AlwaysResolveStickers;
159160
LogGatewayIntentWarnings = config.LogGatewayIntentWarnings;
160161
SuppressUnknownDispatchWarnings = config.SuppressUnknownDispatchWarnings;
162+
IncludeRawPayloadOnGatewayErrors = config.IncludeRawPayloadOnGatewayErrors;
161163
HandlerTimeout = config.HandlerTimeout;
162164
State = new ClientState(0, 0);
163165
Rest = new DiscordSocketRestClient(config, ApiClient);
@@ -3342,6 +3344,13 @@ private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string ty
33423344
}
33433345
catch (Exception ex)
33443346
{
3347+
if (IncludeRawPayloadOnGatewayErrors)
3348+
{
3349+
ex.Data["opcode"] = opCode;
3350+
ex.Data["type"] = type;
3351+
ex.Data["payload_data"] = (payload as JToken).ToString();
3352+
}
3353+
33453354
await _gatewayLogger.ErrorAsync($"Error handling {opCode}{(type != null ? $" ({type})" : "")}", ex).ConfigureAwait(false);
33463355
}
33473356
}

src/Discord.Net.WebSocket/DiscordSocketConfig.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ public int MaxWaitBetweenGuildAvailablesBeforeReady
176176
}
177177
}
178178

179+
/// <summary>
180+
/// Gets or sets whether or not to include the raw payload on gateway errors.
181+
/// </summary>
182+
/// <remarks>
183+
/// Note that this may expose sensitive information to logs. It is recommended to only enable this in
184+
/// cases where you are actively debugging an issue.
185+
/// </remarks>
186+
public bool IncludeRawPayloadOnGatewayErrors { get; set; } = false;
187+
179188
private int maxWaitForGuildAvailable = 10000;
180189

181190
/// <summary>

0 commit comments

Comments
 (0)