Skip to content

Commit b1b18ee

Browse files
committed
Improve error handling for invalid plugin.json files
Previously, installing a plugin with an invalid or corrupted plugin.json would cause an unhandled exception. Now, deserialization errors are caught, a user-friendly error message is shown, and the exception is logged. Added a new localized error message for this scenario in en.xaml.
1 parent 8e4f725 commit b1b18ee

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,19 @@ internal static bool InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
896896
return false;
897897
}
898898

899-
var newMetadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(metadataJsonFilePath));
899+
PluginMetadata newMetadata;
900+
try
901+
{
902+
newMetadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(metadataJsonFilePath));
903+
}
904+
catch (Exception ex)
905+
{
906+
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
907+
Localize.pluginJsonInvalidOrCorrupted());
908+
PublicApi.Instance.LogException(ClassName,
909+
$"Failed to deserialize plugin metadata for plugin {plugin.Name} from file {metadataJsonFilePath}", ex);
910+
return false;
911+
}
900912

901913
if (SameOrLesserPluginVersionExists(newMetadata))
902914
{

Flow.Launcher/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
<system:String x:Key="errorCreatingSettingPanel">Error creating setting panel for plugin {0}:{1}{2}</system:String>
235235
<system:String x:Key="pluginMinimumAppVersionUnsatisfiedTitle">{0} requires Flow {1}+ version to run</system:String>
236236
<system:String x:Key="pluginMinimumAppVersionUnsatisfiedMessage">Flow does not meet the minimum version requirements for {0} to run. Do you want to continue installing it? We recommend updating Flow to the latest version to ensure that {0} works without issues.</system:String>
237+
<system:String x:Key="pluginJsonInvalidOrCorrupted">Failed to install plugin because plugin.json is invalid or corrupted</system:String>
237238

238239
<!-- Setting Plugin Store -->
239240
<system:String x:Key="pluginStore">Plugin Store</system:String>

0 commit comments

Comments
 (0)