mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-12-15 20:34:58 +01:00
Error handling improvements (#92)
* Consolidate plugin errors into single window. * Handle error aggregation and loggin inside error reporter. * Minor logging corrections. * Error popup tweaking
This commit is contained in:
@@ -8,19 +8,45 @@ namespace Observatory
|
||||
{
|
||||
public static class ErrorReporter
|
||||
{
|
||||
public static void ShowErrorPopup(string title, string message)
|
||||
public static void ShowErrorPopup(string title, List<(string error, string detail)> errorList)
|
||||
{
|
||||
// Limit number of errors displayed.
|
||||
StringBuilder displayMessage = new();
|
||||
displayMessage.AppendLine($"{errorList.Count} error{(errorList.Count > 1 ? "s" : string.Empty)} encountered.");
|
||||
var firstFiveErrors = errorList.Take(Math.Min(5, errorList.Count)).Select(e => e.error);
|
||||
displayMessage.AppendJoin(Environment.NewLine, firstFiveErrors);
|
||||
displayMessage.AppendLine();
|
||||
displayMessage.Append("Full error details logged to ObservatoryErrorLog file in your documents folder.");
|
||||
|
||||
if (Avalonia.Application.Current.ApplicationLifetime is Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var errorMessage = MessageBox.Avalonia.MessageBoxManager
|
||||
.GetMessageBoxStandardWindow(new MessageBox.Avalonia.DTO.MessageBoxStandardParams
|
||||
Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
ContentTitle = title,
|
||||
ContentMessage = message,
|
||||
Topmost = true
|
||||
var errorMessage = MessageBox.Avalonia.MessageBoxManager
|
||||
.GetMessageBoxStandardWindow(new MessageBox.Avalonia.DTO.MessageBoxStandardParams
|
||||
{
|
||||
ContentTitle = title,
|
||||
ContentMessage = displayMessage.ToString(),
|
||||
Topmost = true
|
||||
});
|
||||
errorMessage.Show();
|
||||
});
|
||||
errorMessage.Show();
|
||||
}
|
||||
|
||||
// Log entirety of errors out to file.
|
||||
var timestamp = DateTime.Now.ToString("G");
|
||||
StringBuilder errorLog = new();
|
||||
foreach (var error in errorList)
|
||||
{
|
||||
errorLog.AppendLine($"[{timestamp}]:");
|
||||
errorLog.AppendLine($"{error.error} - {error.detail}");
|
||||
errorLog.AppendLine();
|
||||
}
|
||||
|
||||
var docPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
|
||||
System.IO.File.AppendAllText(docPath + System.IO.Path.DirectorySeparatorChar + "ObservatoryErrorLog.txt", errorLog.ToString());
|
||||
|
||||
errorList.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user