Skip to content

Commit

Permalink
fix: catch json exceptions for config
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Apr 28, 2024
1 parent d55a1af commit 2bf2dab
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions MusicX/Services/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public async Task<ConfigModel> GetConfig()
await using var stream = File.OpenRead(_configPath);
config = await JsonSerializer.DeserializeAsync<ConfigModel>(stream, _configSerializerOptions);
}
catch (JsonException e)
{
_logger.Error(e, "Failed to read config");
}
finally
{
ConfigSemaphore.Release();
Expand All @@ -102,6 +106,10 @@ public async Task SetConfig(ConfigModel config)
await using var stream = File.Create(_configPath);
await JsonSerializer.SerializeAsync(stream, config, _configSerializerOptions);
}
catch (JsonException e)
{
_logger.Error(e, "Failed to write config");
}
finally
{
ConfigSemaphore.Release();
Expand Down

0 comments on commit 2bf2dab

Please sign in to comment.