From 1f12c73b2efd1d8a451f75d105b290c830cbe57d Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sun, 9 May 2021 13:56:59 +0200 Subject: [PATCH] Do not throw InvalidOperationException on null Config Lack of config will happen e.g. with invalid submission token, the plugin should not crash in this case, even if it's unusable. --- .../SteamTokenDumperPlugin.cs | 42 ++++--------------- 1 file changed, 7 insertions(+), 35 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs index a79bd358c..87ff98ab4 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs @@ -161,11 +161,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { throw new ArgumentNullException(nameof(bot)); } - if (Config == null) { - throw new InvalidOperationException(nameof(Config)); - } - - if (!Config.Enabled) { + if (Config is not { Enabled: true }) { return; } @@ -192,11 +188,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { subscription.Dispose(); } - if (Config == null) { - throw new InvalidOperationException(nameof(Config)); - } - - if (!Config.Enabled) { + if (Config is not { Enabled: true }) { return; } @@ -224,11 +216,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { throw new ArgumentNullException(nameof(packageChanges)); } - if (Config == null) { - throw new InvalidOperationException(nameof(Config)); - } - - if (!Config.Enabled) { + if (Config is not { Enabled: true }) { return; } @@ -244,11 +232,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { throw new ArgumentOutOfRangeException(nameof(currentChangeNumber)); } - if (Config == null) { - throw new InvalidOperationException(nameof(Config)); - } - - if (!Config.Enabled) { + if (Config is not { Enabled: true }) { return; } @@ -268,11 +252,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { throw new ArgumentNullException(nameof(callback)); } - if (Config == null) { - throw new InvalidOperationException(nameof(Config)); - } - - if (!Config.Enabled) { + if (Config is not { Enabled: true }) { return; } @@ -292,11 +272,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { throw new ArgumentNullException(nameof(bot)); } - if (Config == null) { - throw new InvalidOperationException(nameof(Config)); - } - - if (!Config.Enabled) { + if (Config is not { Enabled: true }) { return; } @@ -471,11 +447,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { throw new InvalidOperationException(nameof(Bot.Bots)); } - if (Config == null) { - throw new InvalidOperationException(nameof(Config)); - } - - if (!Config.Enabled) { + if (Config is not { Enabled: true }) { return; }