Skip to content

Commit 3100f60

Browse files
Fix: Handle JsonException during settings deserialization (#17859)
Co-authored-by: seer-by-sentry[bot] <157164994+seer-by-sentry[bot]@users.noreply.github.com>
1 parent c28044a commit 3100f60

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Files.App/Utils/Serialization/Implementation/DefaultJsonSettingsDatabase.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System.Collections.Concurrent;
5+
using System.Text.Json;
56

67
namespace Files.App.Utils.Serialization.Implementation
78
{
@@ -118,7 +119,16 @@ public virtual bool ImportSettings(object? import)
118119
{
119120
if (obj is JsonElement jElem)
120121
{
121-
return jElem.Deserialize<TValue>();
122+
try
123+
{
124+
return jElem.Deserialize<TValue>();
125+
}
126+
catch (JsonException)
127+
{
128+
// Deserialization failed (e.g., incompatible type in settings file)
129+
// Return null to fall back to the default value
130+
return default;
131+
}
122132
}
123133

124134
return (TValue?)obj;

0 commit comments

Comments
 (0)