mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +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
|
try
|
||||||
{
|
{
|
||||||
string serialized = JsonSerializer.Serialize(_data, _serializerOptions);
|
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();
|
_storageHelper.Close();
|
||||||
|
|
||||||
Log.Info($"Saving cached data at <{FilePath}>", GetType());
|
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)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
Log.Exception($"Error in saving data at <{FilePath}>", e, GetType());
|
Log.Exception($"Error in saving data at <{FilePath}>", e, GetType());
|
||||||
|
|||||||
Reference in New Issue
Block a user