mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[PTRun]Refactor json storage save method for improved robustness and error handling (#31337)
This commit is contained in:
@@ -130,11 +130,18 @@ namespace Wox.Infrastructure.Storage
|
||||
try
|
||||
{
|
||||
string serialized = JsonSerializer.Serialize(_data, _serializerOptions);
|
||||
File.WriteAllText(FilePath, serialized);
|
||||
using var stream = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
using var writer = new StreamWriter(stream);
|
||||
writer.Write(serialized);
|
||||
|
||||
_storageHelper.Close();
|
||||
|
||||
Log.Info($"Saving cached data at <{FilePath}>", GetType());
|
||||
}
|
||||
catch (UnauthorizedAccessException e)
|
||||
{
|
||||
Log.Exception($"Unauthorized access while saving data at <{FilePath}>. Check file permissions.", e, GetType());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Log.Exception($"Error in saving data at <{FilePath}>", e, GetType());
|
||||
|
||||
Reference in New Issue
Block a user