Skip to content

Commit

Permalink
don't set plugin to fail state if we threw InvalidPluginOperationExce…
Browse files Browse the repository at this point in the history
…ption

These are supposed to indicate to the user that they called a function at the wrong point in time. We don't want to actually mutate the state in that case.
  • Loading branch information
goaaats committed Dec 23, 2024
1 parent 8276c19 commit a1ae33b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
16 changes: 16 additions & 0 deletions Dalamud/Plugin/Internal/Exceptions/InternalPluginStateException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Dalamud.Plugin.Internal.Exceptions;

/// <summary>
/// An exception to be thrown when policy blocks a plugin from loading.
/// </summary>
internal class InternalPluginStateException : InvalidPluginOperationException
{
/// <summary>
/// Initializes a new instance of the <see cref="InternalPluginStateException"/> class.
/// </summary>
/// <param name="message">The message to associate with this exception.</param>
public InternalPluginStateException(string message)
: base(message)
{
}
}
11 changes: 8 additions & 3 deletions Dalamud/Plugin/Internal/Types/LocalPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public async Task LoadAsync(PluginLoadReason reason, bool reloading = false)
case PluginState.Unloaded:
if (this.instance is not null)
{
throw new InvalidPluginOperationException(
throw new InternalPluginStateException(
"Plugin should have been unloaded but instance is not cleared");
}

Expand Down Expand Up @@ -413,7 +413,9 @@ public async Task LoadAsync(PluginLoadReason reason, bool reloading = false)
}
catch (Exception ex)
{
this.State = PluginState.LoadError;
// These are "user errors", we don't want to mark the plugin as failed
if (ex is not InvalidPluginOperationException)
this.State = PluginState.LoadError;

// If a precondition fails, don't record it as an error, as it isn't really.
if (ex is PluginPreconditionFailedException)
Expand Down Expand Up @@ -476,7 +478,10 @@ public async Task UnloadAsync(PluginLoaderDisposalMode disposalMode = PluginLoad
}
catch (Exception ex)
{
this.State = PluginState.UnloadError;
// These are "user errors", we don't want to mark the plugin as failed
if (ex is not InvalidPluginOperationException)
this.State = PluginState.UnloadError;

Log.Error(ex, "Error while unloading {PluginName}", this.InternalName);

throw;
Expand Down

0 comments on commit a1ae33b

Please sign in to comment.