feat(feedback): optionally include last exception

This commit is contained in:
goat 2021-09-27 23:49:45 +02:00
parent 689b8fa847
commit ef16e346c6
No known key found for this signature in database
GPG key ID: F18F057873895461
3 changed files with 21 additions and 4 deletions

View file

@ -72,6 +72,7 @@ namespace Dalamud.Interface.Internal.Windows
private bool feedbackModalOnNextFrame = false;
private string feedbackModalBody = string.Empty;
private string feedbackModalContact = string.Empty;
private bool feedbackModalIncludeException = false;
private PluginManifest? feedbackPlugin = null;
private int updatePluginCount = 0;
@ -469,12 +470,14 @@ namespace Dalamud.Interface.Internal.Windows
ImGui.Text(Locs.FeedbackModal_Text);
ImGui.Spacing();
ImGui.InputTextMultiline("Feedback Content", ref this.feedbackModalBody, 1000, new Vector2(400, 200));
ImGui.InputTextMultiline("###FeedbackContent", ref this.feedbackModalBody, 1000, new Vector2(400, 200));
ImGui.Spacing();
ImGui.InputText("Contact Information", ref this.feedbackModalContact, 100);
ImGui.Checkbox("Include last error message", ref this.feedbackModalIncludeException);
ImGui.Spacing();
ImGui.TextColored(ImGuiColors.DalamudGrey, Locs.FeedbackModal_Hint);
@ -486,7 +489,7 @@ namespace Dalamud.Interface.Internal.Windows
{
if (this.feedbackPlugin != null)
{
Task.Run(async () => await BugBait.SendFeedback(this.feedbackPlugin, this.feedbackModalBody, this.feedbackModalContact))
Task.Run(async () => await BugBait.SendFeedback(this.feedbackPlugin, this.feedbackModalBody, this.feedbackModalContact, this.feedbackModalIncludeException))
.ContinueWith(
t =>
{
@ -515,6 +518,7 @@ namespace Dalamud.Interface.Internal.Windows
this.feedbackModalDrawing = true;
this.feedbackModalBody = string.Empty;
this.feedbackModalContact = string.Empty;
this.feedbackModalIncludeException = false;
}
}
@ -2263,7 +2267,7 @@ namespace Dalamud.Interface.Internal.Windows
public static string FeedbackModal_Text => Loc.Localize("InstallerFeedbackInfo", "You can send feedback to the developer of this plugin here.\nYou can include your Discord tag or email address if you wish to give them the opportunity to answer.");
public static string FeedbackModal_Hint => Loc.Localize("InstallerFeedbackHint", "All plugin developers will be able to see your feedback.\nPlease never include any personal or revealing information.\nThe collected feedback is not stored and immediately relayed to Discord.");
public static string FeedbackModal_Hint => Loc.Localize("InstallerFeedbackHint", "All plugin developers will be able to see your feedback.\nPlease never include any personal or revealing information.\nIf you chose to include the last error message, information like your Windows username may be included.\n\nThe collected feedback is not stored on our end and immediately relayed to Discord.");
public static string FeedbackModal_NotificationSuccess => Loc.Localize("InstallerFeedbackNotificationSuccess", "Your feedback was sent successfully!");

View file

@ -22,7 +22,7 @@ namespace Dalamud.Support
/// <param name="content">The content of the feedback.</param>
/// <param name="reporter">The reporter name.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public static async Task SendFeedback(PluginManifest plugin, string content, string reporter)
public static async Task SendFeedback(PluginManifest plugin, string content, string reporter, bool includeException)
{
if (content.IsNullOrWhitespace())
return;
@ -37,6 +37,9 @@ namespace Dalamud.Support
Version = plugin.AssemblyVersion.ToString(),
};
if (includeException)
model.Exception = Troubleshooting.LastException?.ToString();
var postContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
var response = await client.PostAsync(BugBaitUrl, postContent);
@ -56,6 +59,9 @@ namespace Dalamud.Support
[JsonProperty("reporter")]
public string? Reporter { get; set; }
[JsonProperty("exception")]
public string? Exception { get; set; }
}
}
}

View file

@ -19,6 +19,11 @@ namespace Dalamud.Support
/// </summary>
public static class Troubleshooting
{
/// <summary>
/// Gets the most recent exception to occur.
/// </summary>
public static Exception? LastException { get; private set; }
/// <summary>
/// Log the last exception in a parseable format to serilog.
/// </summary>
@ -26,6 +31,8 @@ namespace Dalamud.Support
/// <param name="context">Additional context.</param>
public static void LogException(Exception exception, string context)
{
LastException = exception;
try
{
var payload = new ExceptionPayload