feat: add failing plugins to the installer during boot, handle dependency resolution failures

This commit is contained in:
goaaats 2022-06-29 13:28:33 +02:00
parent 716736f022
commit d9c38a9813
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
4 changed files with 48 additions and 9 deletions

View file

@ -734,13 +734,23 @@ internal partial class PluginManager : IDisposable, IServiceType
{
// Dev plugins always get added to the list so they can be fiddled with in the UI
Log.Information(ex, $"Dev plugin failed to load, adding anyways: {dllFile.Name}");
plugin.Disable(); // Disable here, otherwise you can't enable+load later
// NOTE(goat): This can't work - plugins don't "unload" if they fail to load.
// plugin.Disable(); // Disable here, otherwise you can't enable+load later
}
else if (plugin.IsOutdated)
{
// Out of date plugins get added so they can be updated.
Log.Information(ex, $"Plugin was outdated, adding anyways: {dllFile.Name}");
}
else if (isBoot)
{
// During boot load, plugins always get added to the list so they can be fiddled with in the UI
Log.Information(ex, $"Regular plugin failed to load, adding anyways: {dllFile.Name}");
// NOTE(goat): This can't work - plugins don't "unload" if they fail to load.
// plugin.Disable(); // Disable here, otherwise you can't enable+load later
}
else
{
PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _);
@ -919,7 +929,7 @@ internal partial class PluginManager : IDisposable, IServiceType
if (!dryRun)
{
// Unload if loaded
if (plugin.State == PluginState.Loaded || plugin.State == PluginState.LoadError)
if (plugin.State is PluginState.Loaded or PluginState.LoadError or PluginState.DependencyResolutionFailed)
{
try
{

View file

@ -55,7 +55,16 @@ internal class LocalPlugin : IDisposable
this.DllFile = dllFile;
this.State = PluginState.Unloaded;
this.loader = PluginLoader.CreateFromAssemblyFile(this.DllFile.FullName, SetupLoaderConfig);
try
{
this.loader = PluginLoader.CreateFromAssemblyFile(this.DllFile.FullName, SetupLoaderConfig);
}
catch (InvalidOperationException ex)
{
Log.Error(ex, "Loader.CreateFromAssemblyFile() failed");
this.State = PluginState.DependencyResolutionFailed;
throw;
}
try
{
@ -522,6 +531,8 @@ internal class LocalPlugin : IDisposable
break;
case PluginState.UnloadError:
break;
case PluginState.DependencyResolutionFailed:
throw new InvalidPluginOperationException($"Unable to enable {this.Name}, dependency resolution failed");
default:
throw new ArgumentOutOfRangeException(this.State.ToString());
}
@ -550,6 +561,8 @@ internal class LocalPlugin : IDisposable
break;
case PluginState.UnloadError:
break;
case PluginState.DependencyResolutionFailed:
return; // This is a no-op.
default:
throw new ArgumentOutOfRangeException(this.State.ToString());
}

View file

@ -34,4 +34,9 @@ internal enum PluginState
/// Currently loading.
/// </summary>
Loading,
/// <summary>
/// This plugin couldn't load one of its dependencies.
/// </summary>
DependencyResolutionFailed,
}