2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-07-01 16:33:43 -04: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:
Jonathan Miller
2022-07-24 15:48:55 -02:30
committed by GitHub
parent d8d5f2794b
commit 342d5af11c
7 changed files with 80 additions and 61 deletions

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Observatory.Framework.Files.Journal;
using System.Timers;
namespace Observatory.PluginManagement
{
@ -12,13 +13,20 @@ namespace Observatory.PluginManagement
{
private IEnumerable<IObservatoryWorker> observatoryWorkers;
private IEnumerable<IObservatoryNotifier> observatoryNotifiers;
private List<string> errorList;
private List<(string error, string detail)> errorList;
private Timer timer;
public PluginEventHandler(IEnumerable<IObservatoryWorker> observatoryWorkers, IEnumerable<IObservatoryNotifier> observatoryNotifiers)
{
this.observatoryWorkers = observatoryWorkers;
this.observatoryNotifiers = observatoryNotifiers;
errorList = new();
// Use a timer to delay error reporting until incoming errors are "quiet" for one full second.
// Should resolve issue where repeated plugin errors open hundreds of error windows.
timer = new();
timer.Interval = 1000;
timer.Elapsed += ReportErrorsIfAny;
}
public void OnJournalEvent(object source, JournalEventArgs journalEventArgs)
@ -35,9 +43,9 @@ namespace Observatory.PluginManagement
}
catch (Exception ex)
{
RecordError(ex, worker.Name, journalEventArgs.journalType.Name);
RecordError(ex, worker.Name, journalEventArgs.journalType.Name, ((JournalBase)journalEventArgs.journalEvent).Json);
}
ReportErrorsIfAny();
ResetTimer();
}
}
@ -55,9 +63,9 @@ namespace Observatory.PluginManagement
}
catch (Exception ex)
{
RecordError(ex, worker.Name, journalEventArgs.journalType.Name);
RecordError(ex, worker.Name, journalEventArgs.journalType.Name, ((JournalBase)journalEventArgs.journalEvent).Json);
}
ReportErrorsIfAny();
ResetTimer();
}
}
@ -71,7 +79,7 @@ namespace Observatory.PluginManagement
}
catch (Exception ex)
{
RecordError(ex, worker.Name, "LogMonitorStateChanged event");
RecordError(ex, worker.Name, "LogMonitorStateChanged event", ex.StackTrace);
}
}
}
@ -90,29 +98,35 @@ namespace Observatory.PluginManagement
}
catch (Exception ex)
{
RecordError(ex, notifier.Name, notificationArgs.Title);
RecordError(ex, notifier.Name, notificationArgs.Title, notificationArgs.Detail);
}
ReportErrorsIfAny();
ResetTimer();
}
}
private void ResetTimer()
{
timer.Stop();
timer.Start();
}
private void RecordError(PluginException ex)
{
errorList.Add($"Error in {ex.PluginName}: {ex.Message}");
errorList.Add(($"Error in {ex.PluginName}: {ex.Message}", ex.StackTrace));
}
private void RecordError(Exception ex, string plugin, string eventType)
private void RecordError(Exception ex, string plugin, string eventType, string eventDetail)
{
errorList.Add($"Error in {plugin} while handling {eventType}: {ex.Message}");
errorList.Add(($"Error in {plugin} while handling {eventType}: {ex.Message}", eventDetail));
}
private void ReportErrorsIfAny()
private void ReportErrorsIfAny(object sender, ElapsedEventArgs e)
{
if (errorList.Any())
{
ErrorReporter.ShowErrorPopup($"Plugin Error{(errorList.Count > 1 ? "s" : "")}", string.Join(Environment.NewLine, errorList));
errorList.Clear();
ErrorReporter.ShowErrorPopup($"Plugin Error{(errorList.Count > 1 ? "s" : "")}", errorList);
timer.Stop();
}
}
}

View File

@ -29,7 +29,7 @@ namespace Observatory.PluginManagement
}
public readonly List<string> errorList;
public readonly List<(string error, string detail)> errorList;
public readonly List<Panel> pluginPanels;
public readonly List<DataTable> pluginTables;
public readonly List<(IObservatoryWorker plugin, PluginStatus signed)> workerPlugins;
@ -62,7 +62,7 @@ namespace Observatory.PluginManagement
}
catch (PluginException ex)
{
errorList.Add(FormatErrorMessage(ex));
errorList.Add((FormatErrorMessage(ex), ex.StackTrace));
errorPlugins.Add(plugin);
}
}
@ -82,7 +82,7 @@ namespace Observatory.PluginManagement
}
catch (PluginException ex)
{
errorList.Add(FormatErrorMessage(ex));
errorList.Add((FormatErrorMessage(ex), ex.StackTrace));
errorPlugins.Add(plugin);
}
}
@ -175,11 +175,11 @@ namespace Observatory.PluginManagement
Properties.Core.Default.Save();
}
private static List<string> LoadPlugins(out List<(IObservatoryWorker plugin, PluginStatus signed)> observatoryWorkers, out List<(IObservatoryNotifier plugin, PluginStatus signed)> observatoryNotifiers)
private static List<(string, string)> LoadPlugins(out List<(IObservatoryWorker plugin, PluginStatus signed)> observatoryWorkers, out List<(IObservatoryNotifier plugin, PluginStatus signed)> observatoryNotifiers)
{
observatoryWorkers = new();
observatoryNotifiers = new();
var errorList = new List<string>();
var errorList = new List<(string, string)>();
string pluginPath = $"{AppDomain.CurrentDomain.BaseDirectory}{Path.DirectorySeparatorChar}plugins";
@ -218,7 +218,7 @@ namespace Observatory.PluginManagement
string error = LoadPluginAssembly(dll, observatoryWorkers, observatoryNotifiers);
if (!string.IsNullOrWhiteSpace(error))
{
errorList.Add(error);
errorList.Add((error, string.Empty));
}
//}
//else
@ -230,7 +230,7 @@ namespace Observatory.PluginManagement
}
catch (Exception ex)
{
errorList.Add($"ERROR: {new FileInfo(dll).Name}, {ex.Message}");
errorList.Add(($"ERROR: {new FileInfo(dll).Name}, {ex.Message}", ex.StackTrace));
LoadPlaceholderPlugin(dll, PluginStatus.InvalidLibrary, observatoryNotifiers);
}
}